Re: generic strncpy - off-by-one error

From: Timothy Miller
Date: Mon Aug 18 2003 - 11:28:51 EST




Daniel Forrest wrote:

- if (count) {
+ if (count >= sizeof(long)) {
size_t count2;

I like this size check here, but the comparison should be to some number greater than sizeof(long). There is a threshold below which it's not worth it to do all of the extra loops. If you're going to fill only four bytes, it's probably best to do it just using the last loop.

Maybe through some trial and error, we could determine what that threshold is. I'm betting it's something around 2* or 3* word size.


[snip]

+
+ while (count) {
+ *tmp++ = '\0';
+ count--;
}
return dest;
}



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/