lkml.org 
[lkml]   [2003]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: generic strncpy - off-by-one error


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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:47    [W:0.041 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site