gpsd-dev
[Top][All Lists]
Advanced

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

Re: long long unsigned on 32-bit machines


From: Bernd Zeimetz
Subject: Re: long long unsigned on 32-bit machines
Date: Sun, 26 Jan 2020 16:03:23 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1


On 1/26/20 3:44 PM, Kai Harrekilde-Petersen wrote:
> My guess is that the problem lies in the bit-selection expresion: (1 << i).
> The 1 is a signed int by default, so forcing i to be an uint64_t
> promotes the result to be 64 bit as well, so testing for bit 31 works
> correctly. If this is indeed the problem, use 1UL instead.

Good guess, I think that is the case here.

I guess using
((unsigned int) 1 << i)  would also fix this?


Bernd



> /Kai, shooting from the hip here
> 
> On 26 Jan 2020 15.21, Bernd Zeimetz wrote:
>>
>> On 1/26/20 2:21 PM, Sanjeev Gupta wrote:> I think we should wait for
>> Bernd to chime in.
>>
>> That is just the fix for the change before - unsigned long is still not
>> 64bit on 32bit. I can't remember how I stumbled across it, but I guess
>> some tool pointed it out.
>>
>> After looking at the code again - I have no idea why there is something
>> else than a simple int needed.
>>
>>
>>
>> commit b1b555e0cb37382655a3a7cb37f2f89cb89eda7a
>> Author: Gary E. Miller <address@hidden>
>> Date:   Thu Oct 10 12:19:28 2019 -0700
>>
>>      monitor_italk.c: 32-bit unsigned too small by one.
>>
>>      Problem found by cpplint
>>
>> diff --git a/monitor_italk.c b/monitor_italk.c
>> index 8da7e17ea..6ee79cbf0 100644
>> --- a/monitor_italk.c
>> +++ b/monitor_italk.c
>> @@ -160,11 +160,11 @@ static void display_itk_navfix(unsigned char *buf,
>> size_t len)
>>       (void)wmove(navfixwin, 11, 6);
>>       {
>>          char prn[4], satlist[38];
>> -       unsigned int i;
>> +       unsigned long i;         // unsigned long just in case ints are
>> 32-bit
>>          satlist[0] = '\0';
>>          for (i = 0; i < 32; i++) {
>>              if (svlist & (1 << i)) {
>> -               (void)snprintf(prn, 4, "%u ", i + 1);
>> +               (void)snprintf(prn, 4, "%lu ", i + 1);
>>                  (void)strlcat(satlist, prn, sizeof(satlist));
>>              }
>>          }
>>
>>
>>> -- 
>>> Sanjeev
> 

-- 
 Bernd Zeimetz                            Debian GNU/Linux Developer
 http://bzed.de                                http://www.debian.org
 GPG Fingerprint: ECA1 E3F2 8E11 2432 D485  DD95 EB36 171A 6FF9 435F



reply via email to

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