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

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

Date: Tue, 01 Dec 2009 20:50:03 +0200

To: Carl Worth

Cc: notmuch@notmuchmail org

From: Dirk-Jan C. Binnema


Hi Carl,

>>>>> "Carl" == Carl Worth <cworth@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@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.

0001-notmuch-config-fix-small-leak-from-g_key_file_to_dat.patch (application/octet-stream)

0002-free-the-response-data-from-prompt.patch (application/octet-stream)


Best wishes,
Dirk.

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


Thread: