Warnings from fwrite() in git head

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Warnings from fwrite() in git head
Date: 2012-10-08 15:58:51
Message-ID: 20121008155851.GD7460@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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
zic.c:1514: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1752: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1753: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1754: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1755: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1756: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1757: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1758: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1759: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1760: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.c:1772: warning: ignoring return value of ‘fwrite’, declared with attribute warn_unused_result
zic.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 with warn_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 newline to log file */
if (strchr(message, '\r') != NULL)
rc = fwrite("\n", 1, 1, log_opts.internal);
(void) rc;

which was added by this commit:

commit b98fd52a5516365e4a90d523cfed906eb7b3e67a
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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 comparable code in elog.c,
we may as well do it here.

Should we give zic.c the same treatment?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-10-08 16:04:52 Re: static-if-inline
Previous Message Tom Lane 2012-10-08 15:54:13 Re: Add FET to Default and Europe.txt