This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: nonstrings in Glibc


On 11/20/2017 08:54 AM, Martin Sebor wrote:
I've been looking at other uses of strncpy in Glibc to see if there
are other arrays that would benefit from the attribute.  I'm not
sufficiently familiar with Glibc data structures so it's a very
slow going.  Could someone help suggests data structures with
array members that might be candidates?

If GCC is not warning about uses of the array, what would be the benefit of marking it with __attribute__ ((nonstring))?

Is this because you're thinking of changing GCC so that it warns about strlen(x) where x is marked with __attribute__ ((nonstring))? If so, how would that benefit the typical case? Many char arrays start off being nonstrings, and are later turned into strings by storing '\0' somewhere. Although it's not OK to call strlen on these arrays at first, it's fine to do so later. How would a static attribute capture this typical situation?

The typical situation is distinct from the strncpy case where __attribute__ ((nonstring)) applies throught the array's lifetime. Although I can see that the strlen warning would be useful when code mistakenly applies strlen to strncpy-like arrays, these arrays are quite rare in glibc and you should be able to find them all by looking at uses of strncpy and strncat.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]