[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] symbols.c: Avoid warn_unused_result build failure on fgets().
>>> On 04.11.15 at 12:39, <riku.voipio@xxxxxxxxxx> 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.) > --- 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 */ As to formal things - two such consecutive if()-s should be combined. Since we really want to ignore the return value here, perhaps just cast the function result to void? (I admit that I don't recall whether this would take care of that compiler warning.) Jan _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |