{
size_t i;
- for (i = 0; i < haystack_len - needle_len; i++)
+ for (i = 0; i <= haystack_len - needle_len; i++)
if (!memcmp (haystack + i, needle, needle_len))
return (char *) haystack + i;
}
single string.
strtok_r() modifies the string S, changing delimiters to null
- bytes. Thus, S must be a modifiable string.
+ bytes. Thus, S must be a modifiable string. String literals,
+ in particular, are *not* modifiable in C, even though for
+ backward compatibility they are not `const'.
Example usage:
{
size_t dst_len = size - 1;
if (src_len < dst_len)
- src_len = dst_len;
+ dst_len = src_len;
memcpy (dst, src, dst_len);
dst[dst_len] = '\0';
}