forked from github/server
unfuck str_strlcpy again.
This commit is contained in:
parent
308c9f642f
commit
28cd26f0d9
|
@ -80,9 +80,10 @@ size_t str_strlcpy(char *dst, const char *src, size_t len)
|
|||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (len != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
return (d - dst); /* count does not include NUL */
|
||||
if (len != 0) {
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
}
|
||||
return (s - src) + strlen(s); /* count does not include NUL */
|
||||
}
|
||||
|
||||
return (s - src - 1); /* count does not include NUL */
|
||||
|
@ -287,8 +288,8 @@ void sbs_strcat(struct sbstring *sbs, const char *str)
|
|||
size_t len;
|
||||
assert(sbs);
|
||||
len = sbs->size - (sbs->end - sbs->begin);
|
||||
len = str_strlcpy(sbs->end, str, len);
|
||||
sbs->end += len;
|
||||
str_strlcpy(sbs->end, str, len);
|
||||
sbs->end += strlen(sbs->end);
|
||||
assert(sbs->begin + sbs->size >= sbs->end);
|
||||
}
|
||||
|
||||
|
|
|
@ -119,10 +119,10 @@ static void test_str_strlcpy(CuTest * tc)
|
|||
CuAssertStrEquals(tc, "herp", buffer);
|
||||
CuAssertIntEquals(tc, 0x7f, buffer[5]);
|
||||
|
||||
CuAssertIntEquals(tc, 3, (int)str_strlcpy(buffer, "herp", 4));
|
||||
CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 4));
|
||||
CuAssertStrEquals(tc, "her", buffer);
|
||||
|
||||
CuAssertIntEquals(tc, 7, (int)str_strlcpy(buffer, "herpderp", 8));
|
||||
CuAssertIntEquals(tc, 8, (int)str_strlcpy(buffer, "herpderp", 8));
|
||||
CuAssertStrEquals(tc, "herpder", buffer);
|
||||
CuAssertIntEquals(tc, 0x7f, buffer[8]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue