gpsd-dev
[Top][All Lists]
Advanced

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

Re: [gpsd-dev] Today's warnings....


From: Greg Troxel
Subject: Re: [gpsd-dev] Today's warnings....
Date: Fri, 12 Aug 2016 14:35:09 -0400
User-agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/24.5 (berkeley-unix)

"Gary E. Miller" <address@hidden> writes:

>> From NetBSD
>>   cc (nb2 20150115) 4.8.4
>> test_libgps.c:93:6: warning: array subscript has type 'char' 
>> [-Wchar-subscripts]
>
>             if (buf[0] == '{' || isalpha(buf[0])) {
>
> And that is wrong why?

This is complicated, but the basic point is that isalpha is defined to
take an int, or eof.  The routines, implemented as macros, assume an
int, and use that to index in a table which also has a slot for EOF
(-1).  I am not 100% clear on the fine points, but I've read C99
language lawyer text on this, and the conclusion is that calling
isalpha/etc. with a char is incorrect (IIRC< especially dangerous if it
is a signed type).

http://pubs.opengroup.org/onlinepubs/9699919799/functions/isalpha.html

and why using char is not ok is explained in many of the answers at:

http://stackoverflow.com/questions/23506902/c-programming-warning-array-subscript-has-type-char-wchar-subscripts

So I think you can cast to unsigned char, or to int.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]