[ovs-dev] [PATCH] perf-counter: fix compiler warnings

Andy Zhou azhou at nicira.com
Tue Apr 14 21:50:38 UTC 2015


On Tue, Apr 14, 2015 at 2:33 PM, Ben Pfaff <blp at nicira.com> wrote:
> On Tue, Apr 14, 2015 at 02:27:26PM -0700, 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 <azhou at nicira.com>
>
> Thanks for the fixing the problem.  I have some comments below.
>
>> diff --git a/lib/perf-counter.c b/lib/perf-counter.c
>> index 7bd7834..10cc97f 100644
>> --- a/lib/perf-counter.c
>> +++ b/lib/perf-counter.c
>> @@ -39,8 +39,10 @@ static int fd__ = 0;
>>  uint64_t
>>  perf_counter_read(uint64_t *counter)
>>  {
>> -    if (fd__ > 0) {
>> -        read(fd__, counter, sizeof(*counter));
>> +    if (fd__ <= 0) {
>
> The new test on fd__ looks wrong.  Shouldn't it be >0 or >=0?
>
>> +        if (read(fd__, counter, sizeof(*counter)) < 0) {
>
> Usually we don't use () on the operand of sizeof.
>
> I'd be inclined to test for "< sizeof *counter" instead of < 0 here.
>
>> +            *counter = 0;
>> +        }
>>      } else {
>>          *counter = 0;
>>      }
>
> I guess that you could actually combine the two "if"s into one?

Let me try again with v2, I will try to combine the two ifs.



More information about the dev mailing list