This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: sparc: fix for missing include file
- From: David Miller <davem at davemloft dot net>
- To: eggert at cs dot ucla dot edu
- Cc: neleai at seznam dot cz, wbx at openadk dot org, libc-alpha at sourceware dot org
- Date: Sat, 13 Dec 2014 14:32:10 -0500 (EST)
- Subject: Re: sparc: fix for missing include file
- Authentication-results: sourceware.org; auth=none
- References: <20141211 dot 150535 dot 106178897111220975 dot davem at davemloft dot net> <20141213 dot 130022 dot 1182209281374969366 dot davem at davemloft dot net> <548C8EBF dot 6010003 at cs dot ucla dot edu>
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 13 Dec 2014 11:08:47 -0800
> David Miller wrote:
>> strncat.c: In function ʽstrncatʼ:
>> strncat.c:76:6: error: ʽcʼ may be used uninitialized in this function
>> [-Werror=uninitialized]
>>
>> This is the generic C strncat.c in string/strncat.c, and actually the
>> compiler is right here in that when 'n' is zero 'c' will in fact be
>> tested without being initialized to anything.
>
> That's amusing, since the code works regardless of whether 'c' is
> initialized properly, assuming that using an uninitialized value
> doesn't trap or have similarly bad behavior. So this looks like
> another candidate for adding pragmas to suppress the diagnostic. In
> Gnulib we'd say 'char c IF_LINT (= 0);'.
How does the code "work"? The test of 'c' against '\0' at the end of
the function happens even if 'n' is passed as zero in which case 'c'
will not be initialized at all.