diff mbox

[Xen-devel] symbols.c: Avoid warn_unused_result build failure on fgets().

Message ID 1446637199-18119-1-git-send-email-riku.voipio@linaro.org
State New
Headers show

Commit Message

Riku Voipio Nov. 4, 2015, 11:39 a.m. UTC
In commit:

d37d63d symbols: prefix static symbols with their source file names

An unchecked fgets was added. This causes a compile error:

symbols.c: In function 'read_symbol':
symbols.c:181:3: error: ignoring return value of 'fgets', declared with
attribute warn_unused_result [-Werror=unused-result]
   fgets(str, 500, in); /* discard rest of line */
   ^

Paper over the warning like in the other similar fgets-on-error-path
earlier in the same file.

Cc: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>

---
 xen/tools/symbols.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.6.2


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

Comments

Riku Voipio Nov. 9, 2015, 8:29 a.m. UTC | #1
Hi,

On 9 November 2015 at 10:10, Jan Beulich <JBeulich@suse.com> wrote:
>>>> On 09.11.15 at 06:03, <haozhong.zhang@intel.com> wrote:

>> On 11/04/15 07:04, Jan Beulich wrote:

>>> >>> On 04.11.15 at 12:39, <riku.voipio@linaro.org> wrote:

>>> > In commit:

>>> >

>>> > d37d63d symbols: prefix static symbols with their source file names

>>> >

>>> > An unchecked fgets was added. This causes a compile error:

>>> >

>>> > symbols.c: In function 'read_symbol':

>>> > symbols.c:181:3: error: ignoring return value of 'fgets', declared with

>>> > attribute warn_unused_result [-Werror=unused-result]

>>> >    fgets(str, 500, in); /* discard rest of line */

>>> >    ^

>>> >

>>> > Paper over the warning like in the other similar fgets-on-error-path

>>> > earlier in the same file.

>>>

>>> But the two cases are dissimilar - the original one skips a line the

>>> format of which is not recognized, while here you may be converting

>>> success into an error. (I did notice the comment on the earlier fgets(),

>>> but since so far I didn't get any compiler warning on any system I

>>> built this on, I assumed we'd be fine without the check, since if we

>>> need the check, then it will end up even more clumsy than the other

>>> one.)

>>>

>>

>> Hi Riku and Jan,

>>

>> Will there be any fix for this error? I got the same error when

>> compiling Xen (commit 6f04de6) by gcc 4.8.4 on Ubuntu 14.04.3. And

>> adding "(void)" ahead of fgets() in the existing code cannot eliminate

>> the error/warning message.


> I expect / welcome an (updated) patch.


Sorry, I missed this mail thread. I'll dive into fixing the patch asap.

Riku

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
diff mbox

Patch

diff --git a/xen/tools/symbols.c b/xen/tools/symbols.c
index dbf6a1a..7e75be2 100644
--- a/xen/tools/symbols.c
+++ b/xen/tools/symbols.c
@@ -178,8 +178,8 @@  static int read_symbol(FILE *in, struct sym_entry *s)
 
  skip_tail:
 	if (input_format == fmt_sysv)
-		fgets(str, 500, in); /* discard rest of line */
-
+		if (fgets(str, 500, in) == NULL) /* discard rest of line */
+			return -1; /* must check fgets result */
 	return rc;
 }