Обсуждение: Warnings from fwrite() in git head

Поиск
Список
Период
Сортировка

Warnings from fwrite() in git head

От
Bruce Momjian
Дата:
I am seeing the following warnings in git head from zic.c:
zic.c:1505: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_resultzic.c:1514: warning:
ignoringreturn value of ‘fwrite’, declared with attribute warn_unused_resultzic.c:1752: warning: ignoring return value
of‘fwrite’, declared with attribute warn_unused_resultzic.c:1753: warning: ignoring return value of ‘fwrite’, declared
withattribute warn_unused_resultzic.c:1754: warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1755:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1756:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1757:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1758:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1759:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1760:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1772:warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_resultzic.c:1785:warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
 

Here is the first C line that generated the warning message:
    (void) fwrite((void *) buf, (size_t) sizeof buf, (size_t) 1, fp);

Seems casting to void is not enough.  Not sure why the error just
started appearing for me last week.  I don't see any recent gcc updates.
This is gcc version 4.4.5-8 on Debian Squeeze.  

However, the only place I see fwrite() cast to void is in zic.c, and I
see this code in pg_upgrade/utils.c:
       /*        * There's nothing much we can do about it if fwrite fails, but some        * platforms declare fwrite
withwarn_unused_result.  Do a little        * dance with casting to void to shut up the compiler in such cases.
*/      size_t      rc;
 
       rc = fwrite(message, strlen(message), 1, log_opts.internal);       /* if we are using OVERWRITE_MESSAGE, add
newlineto log file */       if (strchr(message, '\r') != NULL)           rc = fwrite("\n", 1, 1, log_opts.internal);
  (void) rc;
 

which was added by this commit:
commit b98fd52a5516365e4a90d523cfed906eb7b3e67aAuthor: Tom Lane <tgl@sss.pgh.pa.us>Date:   Wed Sep 5 14:36:47 2012
-0400   Silence -Wunused-result warning in contrib/pg_upgrade.    This is just neatnik-ism, but since we do it for
comparablecode in elog.c,    we may as well do it here.
 

Should we give zic.c the same treatment?

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + It's impossible for everything to be true. +



Re: Warnings from fwrite() in git head

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.us> writes:
> I am seeing the following warnings in git head from zic.c:
>     zic.c:1505: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result

Yeah, this is probably a consequence of the _FORTIFY_SOURCE addition.
I believe that ratchets up warning pickiness as well as other things.

I'm inclined to think we should make zic.c bail out on write errors.
Otherwise, "make install" could fail to notice an out-of-disk-space
situation during install.  The analogy you are drawing to ignoring
errors while writing log messages is quite faulty.

We're overdue for another round of syncing the tz code with upstream,
too.  Might be best to do that first, just in case Olson's crew already
fixed this.
        regards, tom lane



Re: Warnings from fwrite() in git head

От
Jeff Janes
Дата:
On Mon, Oct 8, 2012 at 8:58 AM, Bruce Momjian <bruce@momjian.us> wrote:
> I am seeing the following warnings in git head from zic.c:
>
>         zic.c:1505: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
...
>
> Seems casting to void is not enough.  Not sure why the error just
> started appearing for me last week.  I don't see any recent gcc updates.
> This is gcc version 4.4.5-8 on Debian Squeeze.

I think it was the addition of _FORTIFY_SOURCE

I get the warnings in zic.c, but also I was also getting them in a
different file.  But now I only see zic ones in newest HEAD.

Cheers,

Jeff



Re: Warnings from fwrite() in git head

От
Bruce Momjian
Дата:
On Mon, Oct  8, 2012 at 12:12:54PM -0400, Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > I am seeing the following warnings in git head from zic.c:
> >     zic.c:1505: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
> 
> Yeah, this is probably a consequence of the _FORTIFY_SOURCE addition.
> I believe that ratchets up warning pickiness as well as other things.
> 
> I'm inclined to think we should make zic.c bail out on write errors.
> Otherwise, "make install" could fail to notice an out-of-disk-space
> situation during install.  The analogy you are drawing to ignoring
> errors while writing log messages is quite faulty.
> 
> We're overdue for another round of syncing the tz code with upstream,
> too.  Might be best to do that first, just in case Olson's crew already
> fixed this.

My warnings have disappeared now that _FORTIFY_SOURCE has been removed
on Linux.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + It's impossible for everything to be true. +



Re: Warnings from fwrite() in git head

От
Tom Lane
Дата:
Bruce Momjian <bruce@momjian.us> writes:
> On Mon, Oct  8, 2012 at 12:12:54PM -0400, Tom Lane wrote:
>> I'm inclined to think we should make zic.c bail out on write errors.
>> Otherwise, "make install" could fail to notice an out-of-disk-space
>> situation during install.

> My warnings have disappeared now that _FORTIFY_SOURCE has been removed
> on Linux.

I think it still behooves us to fix that, though.
        regards, tom lane