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