Re: [PATCH v2 3/7] Create helper functions to deal with handles on interactive gatttool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Johan,

On Wed, Feb 23, 2011 at 12:09 AM, Johan Hedberg <johan.hedberg@xxxxxxxxx> wrote:
> Hi Sheldon,
>
> On Tue, Feb 22, 2011, Sheldon Demario wrote:
>> +     *dst = strtoll(src, &e, 16);
>> +     if (errno != 0 || *e != '\0') {
>> +             return -1;
>>       }
>
> Firstly, you've got a coding style issue here: no {} for one-line
> scopes. Secondly, are you sure that this is the right way to check for
> strtoll failure? If there was some earlier libc function that failed
> errno might be set to != 0 even if strtoll succeeds, right? Or are all
> errno using libc functions guaranteed to set errno to 0 on success?
> Reading the man-page of strtoll it seems you should be checking for
> LLONG_MIN and LLONG_MAX return values.

Looking at "man errno", it is not guaranteed for errno to be set to
zero on success, therefore the recommended way is to set it to zero
prior to calling the function to be checked.

The NOTES section from "man strtoll" recommends using errno when
checking for errors:

"Since strtol() can legitimately return 0, LONG_MAX, or LONG_MIN
(LLONG_MAX or LLONG_MIN for strtoll()) on both success and failure,
the calling program  should  set errno to 0 before the call, and then
determine if an error occurred by checking whether errno has a
non-zero value after the call."

So I think the only missing bit here it to set errno to zero prior to
calling strtoll()

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux