[notmuch] [PATCH 2/2] * avoid gcc 4.4.1 compiler warning due to ignored 'fflush' return value

Dirk-Jan C. Binnema djcb.bulk at gmail.com
Tue Dec 1 10:50:03 PST 2009


Hi Carl,

>>>>> "Carl" == Carl Worth <cworth at cworth.org> writes:

    Carl> [1  <text/plain (quoted-printable)>]
    Carl> On Mon, 23 Nov 2009 08:21:50 +0200, Dirk-Jan C. Binnema <djcb.bulk at gmail.com> wrote:
    >> -#define prompt(format, ...)				\
    >> -    do {						\
    >> -	printf (format, ##__VA_ARGS__);			\
    >> -	fflush (stdout);				\
    >> -	getline (&response, &response_size, stdin);	\
    >> -	chomp_newline (response);			\
    >> +#define prompt(format, ...)					\
    >> +    do {							\
    >> +	int ignored;						\
    >> +	printf (format, ##__VA_ARGS__);				\
    >> +	fflush (stdout);					\
    >> +	ignored = getline (&response, &response_size, stdin);	\
    >> +	chomp_newline (response);				\
    >> } while (0)

    Carl> This patch is incorrect. Ignoring the return value of getline results in
    Carl> the program invoking undefined behavior by reading uninitialized
    Carl> memory. This is easily tested by, for example, typing Control-D to
    Carl> provide EOF to a prompt from "notmuch setup".

    Carl> How about just exiting in case of EOF as in the patch below?

Sure, that's the better solution, but note that my patch did not introduce the
undefined behavior -- it was there before. I was trying a minimal patch to
silencing the warning. Note that prompt seems to leak a bit, even after the
committed patch; attached are two more micro patches to fix this and another
small leak. I try to do minimal changes, but the prompt business gets a bit
unwieldy. The leaks are one-time at not critical, but anyway it's always good
stay vigilant.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-notmuch-config-fix-small-leak-from-g_key_file_to_dat.patch
Type: application/octet-stream
Size: 491 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091201/6a42087a/attachment.obj>
-------------- next part --------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-free-the-response-data-from-prompt.patch
Type: application/octet-stream
Size: 1674 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20091201/6a42087a/attachment-0001.obj>
-------------- next part --------------



Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb at djcbsoftware.nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C



More information about the notmuch mailing list