4 ms·
I don't get the fuzz. This is like the 3rd or 4th submission about this function. And all it does is testing that > ((SIZE_MAX / nmemb) >= size) before doing
by vyqfi 12y ago
I don't get the fuzz. This is like the 3rd or 4th submission about this function. And all it does is testing that
> ((SIZE_MAX / nmemb) >= size)
before doing the size_t multiplication. That's no rocket science. Anyone who's worried about his size_ts overflowing should be able to come up with this.
- quotemstr 12y agoI don't understand why more people don't define local helper functions. I've worked on FOSS codebases with hundreds of invocations of strncpy, each carefully followed with an additional NUL-termination check to work around strncpy's well-known problem. Why wouldn't you just write a little wrapper?
- PythonicAlpha 12y agoIn my opinion the C library was one of C's most best innovations. But there are also some dark spots. strncpy is one of it -- and one of the things, where the C library is gravely outdated today.
- drv 12y agoProgrammers just use the wrong tool for the job - arguably because strncpy is poorly named. strncpy is intended for filling zero-padded fixed-size strings, not copying normal single-zero-terminated strings. I think the main benefit of adding functions like reallocarray is that they make the right tool for the job available by default. Plain realloc for array resizing is a timebomb in the same way as strncpy for normal strings - it will work (by accident) until it doesn't, and when it fails, it's likely to be an exploitable security hole.