nonstrings in Glibc

Paul Eggert eggert@cs.ucla.edu
Mon Nov 20 17:59:00 GMT 2017


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.



More information about the Libc-alpha mailing list