[PATCH] Faster strn?cat

Kalle Olavi Niemitalo kon@iki.fi
Sun Jun 17 07:50:00 GMT 2012


Ondrej Bilka <neleai@seznam.cz> writes:

>  char *
> -STRNCAT (char *s1, const char *s2, size_t n)
> +STRNCAT (char *d, const char *s, size_t n)
>  {

[...]

> +	return 	strncpy(d+strlen(d),s,n);
>  }

Returns the wrong value; should return d always.
Does not append a null character if strlen(s) >= n.
Appends too many null characters if strlen(s) + 1 < n.

It seems test_strncat in string/tester.c should have detected
these errors.  Did you run the test suite?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120617/931a9157/attachment.sig>


More information about the Libc-alpha mailing list