]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: correctly display signed single byte integers
authorSamir Benmendil <me@rmz.io>
Wed, 9 Jun 2021 00:21:46 +0000 (01:21 +0100)
committerSamir Benmendil <me@rmz.io>
Wed, 9 Jun 2021 00:21:46 +0000 (01:21 +0100)
When using the format string '/1 "%d"', the byte did not display as a
signed integer as expected, it was interpreted as unsigned.

text-utils/hexdump-display.c

index 695b4724b5607310ed7f8fbf82b1afb549f29da6..bc92bd0ca027481089dbdb673b95ca10204497e4 100644 (file)
@@ -145,13 +145,15 @@ print(struct hexdump_pr *pr, unsigned char *bp) {
            }
        case F_INT:
            {
+               char cval;      /* int8_t */
                short sval;     /* int16_t */
                int ival;       /* int32_t */
                long long Lval; /* int64_t, int64_t */
 
                switch(pr->bcnt) {
                case 1:
-                       printf(pr->fmt, (unsigned long long) *bp);
+                       memmove(&cval, bp, sizeof(cval));
+                       printf(pr->fmt, (unsigned long long) cval);
                        break;
                case 2:
                        memmove(&sval, bp, sizeof(sval));