small changes to hexdump code to stop a gcc warning on platforms where sizeof(int) != sizeof(int*) e.g. x86_64

Wed, 05 Aug 2009 15:00:54 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 05 Aug 2009 15:00:54 +0100
changeset 12
96e1df9bd27c
parent 11
69416826d18c
child 13
a933b13e087f

small changes to hexdump code to stop a gcc warning on platforms where sizeof(int) != sizeof(int*) e.g. x86_64

src/hexdump.c file | annotate | diff | revisions
     1.1 --- a/src/hexdump.c	Mon Aug 03 23:41:04 2009 +0100
     1.2 +++ b/src/hexdump.c	Wed Aug 05 15:00:54 2009 +0100
     1.3 @@ -11,6 +11,7 @@
     1.4       */
     1.5  
     1.6      unsigned char *p = data;
     1.7 +    unsigned long addr = 0;
     1.8      unsigned char c;
     1.9      int n;
    1.10      char bytestr[4] = {0};
    1.11 @@ -20,8 +21,8 @@
    1.12      for(n=1;n<=size;n++) {
    1.13          if (n%16 == 1) {
    1.14              /* store address for this line */
    1.15 -            snprintf(addrstr, sizeof(addrstr), "%.4x",
    1.16 -               ((unsigned int)p-(unsigned int)data) );
    1.17 +            snprintf(addrstr, sizeof(addrstr), "%.4lX",
    1.18 +               addr);
    1.19          }
    1.20              
    1.21          c = *p;
    1.22 @@ -48,6 +49,7 @@
    1.23              strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1);
    1.24          }
    1.25          p++; /* next byte */
    1.26 +		addr++; /* increment address */
    1.27      }
    1.28  
    1.29      if (strlen(hexstr) > 0) {