diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-11-28 17:40:10 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-11-28 17:40:10 +0000 |
commit | 59bf40d2b1cfe85111b15ec05f8c124f657aefe2 (patch) | |
tree | 537b064ccd3a64d7c966b22bc2271ccef8719a31 /converter | |
parent | 904c1e64ad0d672c04c1c28e0f0d760b0e7c7cae (diff) | |
download | netpbm-mirror-59bf40d2b1cfe85111b15ec05f8c124f657aefe2.tar.gz netpbm-mirror-59bf40d2b1cfe85111b15ec05f8c124f657aefe2.tar.xz netpbm-mirror-59bf40d2b1cfe85111b15ec05f8c124f657aefe2.zip |
Explicit two's complement interpretation for systems (eg ppc64) where 'char' is unsigned
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4197 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/pnmtopalm/palmtopnm.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c index 445f7839..a2c644b7 100644 --- a/converter/other/pnmtopalm/palmtopnm.c +++ b/converter/other/pnmtopalm/palmtopnm.c @@ -825,11 +825,12 @@ readPackBitsRow16(FILE * const ifP, unsigned int j; for (j = 0; j < bytesPerRow; ) { - char incount; - pm_readchar(ifP, &incount); - if (incount < 0) { + unsigned char incountByte; + pm_readcharu(ifP, &incountByte); + if (incountByte & 0x80) { + int const signedIncount = (signed char)incountByte; /* How do we handle incount == -128 ? */ - unsigned int const runlength = (-incount + 1) * 2; + unsigned int const runlength = (-signedIncount + 1) * 2; unsigned int k; unsigned short inval; pm_readlittleshortu(ifP, &inval); @@ -840,7 +841,7 @@ readPackBitsRow16(FILE * const ifP, j += runlength; } else { /* We just read the stream of shorts as a stream of chars */ - unsigned int const nonrunlength = (incount + 1) * 2; + unsigned int const nonrunlength = (incountByte + 1) * 2; unsigned int k; for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) { unsigned char inval; @@ -868,18 +869,19 @@ readPackBitsRow(FILE * const ifP, unsigned int j; for (j = 0; j < bytesPerRow; ) { - char incount; - pm_readchar(ifP, &incount); - if (incount < 0) { + unsigned char incountByte; + pm_readcharu(ifP, &incountByte); + if (incountByte & 0x80) { /* How do we handle incount == -128 ? */ - unsigned int const runlength = -incount + 1; + int const signedIncount = (char)incountByte; + unsigned int const runlength = -signedIncount + 1; unsigned char inval; pm_readcharu(ifP, &inval); if (j + runlength <= bytesPerRow) memset(palmrow + j, inval, runlength); j += runlength; } else { - unsigned int const nonrunlength = incount + 1; + unsigned int const nonrunlength = incountByte + 1; unsigned int k; for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) { unsigned char inval; |