From b7805868f7e8a969af22dbb9bff88cb685c6bcd0 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 26 Dec 2014 17:29:54 +0000 Subject: [PATCH] cache1d.c: in (de)compr. funcs, add an bound-checking assert that fails w/ AMC TC. Also, formatting. git-svn-id: https://svn.eduke32.com/eduke32@4837 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/cache1d.c | 41 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index 89190c409..dc88d00c2 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -1463,8 +1463,7 @@ static uint32_t decompress_part(intptr_t f, uint32_t *kgoalptr) // Read from 'f' into 'buffer'. C1D_STATIC int32_t c1d_read_compressed(void *buffer, bsize_t dasizeof, bsize_t count, intptr_t f) { - uint32_t i, j, k, kgoal; - char *ptr; + char *ptr = (char *)buffer; if (dasizeof > LZWSIZE) { @@ -1475,21 +1474,23 @@ C1D_STATIC int32_t c1d_read_compressed(void *buffer, bsize_t dasizeof, bsize_t c } else { - i = count; + uint32_t i = count; count = dasizeof; dasizeof = i; } } - ptr = (char *)buffer; + uint32_t kgoal; - k = decompress_part(f, &kgoal); - if (k) return -1; + if (decompress_part(f, &kgoal)) + return -1; + Bassert(dasizeof < sizeof(lzwrawbuf)); Bmemcpy(ptr, lzwrawbuf, (int32_t)dasizeof); - k += (int32_t)dasizeof; - for (i=1; i= kgoal) { @@ -1497,14 +1498,16 @@ C1D_STATIC int32_t c1d_read_compressed(void *buffer, bsize_t dasizeof, bsize_t c if (k) return -1; } - j = 0; + uint32_t j = 0; if (dasizeof >= 4) { for (; j LZWSIZE && count > LZWSIZE) @@ -1552,28 +1554,31 @@ C1D_STATIC void c1d_write_compressed(const void *buffer, bsize_t dasizeof, bsize } else { - i = count; + uint32_t i = count; count = dasizeof; dasizeof = i; } } + Bassert(dasizeof < sizeof(lzwrawbuf)); Bmemcpy(lzwrawbuf, ptr, (int32_t)dasizeof); - k = dasizeof; + uint32_t k = dasizeof; if (k > LZWSIZE-dasizeof) k = compress_part(k, f); - for (i=1; i= 4) { for (; j