diff options
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/fitstopnm.c | 18 | ||||
-rw-r--r-- | converter/ppm/ilbmtoppm.c | 4 |
2 files changed, 20 insertions, 2 deletions
diff --git a/converter/other/fitstopnm.c b/converter/other/fitstopnm.c index b143882b..b4240d63 100644 --- a/converter/other/fitstopnm.c +++ b/converter/other/fitstopnm.c @@ -359,6 +359,22 @@ main(int argc, char * argv[]) { exit( 0 ); } + +static void +swapbytes(void * const p, + unsigned int const nbytes) { +#if BYTE_ORDER == LITTLE_ENDIAN + unsigned char * const c = p; + unsigned int i; + for (i = 0; i < nbytes/2; ++i) { + unsigned char const orig = c[i]; + c[i] = c[nbytes-(i+1)]; + c[nbytes-(i+1)] = orig; + } +#endif +} + + /* ** This code will deal properly with integers, no matter what the byte order ** or integer size of the host machine. Sign extension is handled manually @@ -427,6 +443,7 @@ read_val (fp, bitpix, vp) pm_error( "EOF / read error" ); c[i] = ich; } + swapbytes(c, 4); *vp = *( (float *) c); break; @@ -437,6 +454,7 @@ read_val (fp, bitpix, vp) pm_error( "EOF / read error" ); c[i] = ich; } + swapbytes(c, 8); *vp = *( (double *) c); break; diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c index fafbd005..c88cdfb2 100644 --- a/converter/ppm/ilbmtoppm.c +++ b/converter/ppm/ilbmtoppm.c @@ -1675,7 +1675,7 @@ PCHG_Decompress(PCHG, CompHdr, compdata, compsize, comptree, data) #endif /* turn big-endian 2-byte shorts into native format */ huffsize = treesize/2; - MALLOCVAR_NOFAIL(hufftree); + MALLOCARRAY_NOFAIL(hufftree, huffsize); for( i = 0; i < huffsize; i++ ) { hufftree[i] = (short)BIG_WORD(comptree); comptree += 2; @@ -1932,7 +1932,7 @@ read_pchg(FILE * const ifp, get_big_long(ifp, iffid, &remainingChunksize); treesize = CompHdr.CompInfoSize; - MALLOCVAR_NOFAIL(comptree); + MALLOCARRAY_NOFAIL(comptree, treesize); read_bytes(ifp, treesize, comptree, iffid, &remainingChunksize); compsize = remainingChunksize; |