On Tue, Apr 14, 2015 at 4:48 PM, Russell Bryant <rbry...@redhat.com> wrote: > On 04/14/2015 06:56 PM, Ben Pfaff wrote: >> On Tue, Apr 14, 2015 at 03:16:22PM -0700, Andy Zhou wrote: >>> On Tue, Apr 14, 2015 at 2:55 PM, Russell Bryant <rbry...@redhat.com> wrote: >>>> On 04/14/2015 05:51 PM, Andy Zhou wrote: >>>>> Gcc complains about: >>>>> lib/perf-counter.c:43:13: error: ignoring return value of 'read', >>>>> declared with attribute warn_unused_result [-Werror=unused-result] >>>>> read(fd__, counter, sizeof(*counter)); >>>>> >>>>> Signed-off-by: Andy Zhou <az...@nicira.com> >>>>> >>>>> --- >>>>> v1->v2: Combine two 'if's into using only one. >>>>> --- >>>>> lib/perf-counter.c | 6 +++--- >>>>> 1 file changed, 3 insertions(+), 3 deletions(-) >>>>> >>>>> diff --git a/lib/perf-counter.c b/lib/perf-counter.c >>>>> index 7bd7834..a6e63ac 100644 >>>>> --- a/lib/perf-counter.c >>>>> +++ b/lib/perf-counter.c >>>>> @@ -39,9 +39,9 @@ static int fd__ = 0; >>>>> uint64_t >>>>> perf_counter_read(uint64_t *counter) >>>>> { >>>>> - if (fd__ > 0) { >>>>> - read(fd__, counter, sizeof(*counter)); >>>>> - } else { >>>>> + int size = sizeof *counter; >>>> >>>> Minor nit ... this should be size_t instead of int. >>>> >>> Thanks, I wlll make the suggested changes. >> >> I'm pretty sure that using size_t instead of int will actually bust >> this. read returns ssize_t, a signed type, and C says that in an >> expression like "ssize_t < size_t" the left-hand operand gets >> converted to size_t. Thus, if "read" returns -1, it gets converted to >> SIZE_MAX, which is not less than sizeof *counter. >> >> If I'm correct, then size should be declared as int or ssize_t. >> > > Oops, thanks for catching that, Ben.
There is very little in C more subtle than the integer promotion rules. I worry that we get these wrong in important ways. -- "I don't normally do acked-by's. I think it's my way of avoiding getting blamed when it all blows up." Andrew Morton _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev