diff options
Diffstat (limited to 'src/tc-string.c')
-rw-r--r-- | src/tc-string.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/tc-string.c b/src/tc-string.c index 112a845..6e85f66 100644 --- a/src/tc-string.c +++ b/src/tc-string.c @@ -160,8 +160,8 @@ static void t_split(void) memcpy(t2, t1, sizeof(t1)); a0 = HX_split(t1, ":", &f0, 0); - a1 = HX_split4(t1, ":", &f1, 0); - f2 = HX_split5(t2, ":", ARRAY_SIZE(a2), a2); + a1 = HX_split_inplace(t1, ":", &f1, 0); + f2 = HX_split_fixed(t2, ":", ARRAY_SIZE(a2), a2); /* complete allocation */ printf("HX_split1: a0[%p]:", a0); @@ -170,7 +170,7 @@ static void t_split(void) printf("\n"); /* array allocated */ - printf("HX_split4: a1[%p]:", a1); + printf("HX_split_inplace: a1[%p]:", a1); for (wp = a1; *wp != NULL; ++wp) printf(" %s[%p]", *wp, *wp); printf("\n"); @@ -202,6 +202,8 @@ extern char *f_strlcpy_mem(char *, const char *, size_t); EXPORT_SYMBOL char *f_strlcpy_str(char *d, const char *s, size_t n) { + if (n == 0) + return d; strncpy(d, s, n); d[n-1] = '\0'; return d; @@ -279,6 +281,13 @@ static void t_strlcpy(void) } } +static void t_strlcpy2(void) +{ + char a[3] = {49, 49, 49}; + HX_strlcpy(&a[1], &a[1], 0); + assert(a[0] == 49 && a[0] == a[1] && a[1] == a[2]); +} + int main(int argc, const char **argv) { hxmc_t *tx = NULL; @@ -308,6 +317,7 @@ int main(int argc, const char **argv) t_split(); t_split2(); t_strlcpy(); + t_strlcpy2(); HXmc_free(tx); HX_exit(); return EXIT_SUCCESS; |