deviceid / diveid weirdness

Thiago Macieira thiago at macieira.org
Fri Nov 22 13:24:38 UTC 2013


On sexta-feira, 22 de novembro de 2013 13:12:24, Linus Torvalds wrote:
> On Fri, Nov 22, 2013 at 12:48 PM, Dirk Hohndel <dirk at hohndel.org> wrote:
> > Some users get deviceid and diveid entries above 0x80000000 "truncated"
> > into 0x7fffffff. But apparently only after downloading additional dives
> > on top of existing ones.
> 
> Ugh.
> 
> I think we need to fix hex_value() in parse-xml.c to use "strtoul()".
> 
> The problem is hidden on 64-bit builds.
> 
> Totally untested, but that would seem to explain it.

Yup, exactly right.

$ cat strol-test.c
#include <stdio.h>
#include <stdlib.h>

typedef unsigned uint32_t;

static void hex_value(char *buffer, void *_i)
{
    uint32_t *i = _i;
    *i = strtol(buffer, NULL, 16);
}

int main(int argc, char **argv)
{
    uint32_t i;
    hex_value(argv[1], &i);
    printf("%x\n", i);
}
$ gcc strtol-test.c
$ ./a.out e04d0248
e04d0248
$ gcc -m32 strtol-test.c
$ ./a.out e04d0248      
7fffffff


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20131122/315b31c4/attachment.sig>


More information about the subsurface mailing list