diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-12-22 23:33:40 +0300 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-12-22 23:42:03 +0300 |
commit | faaad6e75d82f3228298b01a61b08eb37ca10bb4 (patch) | |
tree | 546b900454bd632b2fba4a2036da9a39e6c4e63d /sync.c | |
parent | f064c1cb02b06a8981121f9e44c31bd6878bbbe1 (diff) | |
download | nasm-faaad6e75d82f3228298b01a61b08eb37ca10bb4.tar.gz nasm-faaad6e75d82f3228298b01a61b08eb37ca10bb4.tar.bz2 nasm-faaad6e75d82f3228298b01a61b08eb37ca10bb4.zip |
sync.c: Get sync points limit back
We should explicitly check if we can hold the sync
point, otherwise we may wrap the array index and
reach incorrect value (if we're lucky).
So instead we make the index "almost" unlmited.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'sync.c')
-rw-r--r-- | sync.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -45,7 +45,11 @@ #include "nasmlib.h" #include "sync.h" -#define SYNC_MAX 4096 /* max # of sync points (initial) */ +#define SYNC_MAX_SHIFT 31 +#define SYNC_MAX_SIZE (1U << SYNC_MAX_SHIFT) + +/* initial # of sync points (*must* be power of two)*/ +#define SYNC_INITIAL_CHUNK (1U << 12) /* * This lot manages the current set of sync points by means of a @@ -57,7 +61,7 @@ static struct Sync { uint32_t length; } *synx; -static int max_synx, nsynx; +static uint32_t max_synx, nsynx; static inline void swap_sync(uint32_t dst, uint32_t src) { @@ -68,17 +72,19 @@ static inline void swap_sync(uint32_t dst, uint32_t src) void init_sync(void) { - max_synx = SYNC_MAX - 1; - synx = nasm_malloc(SYNC_MAX * sizeof(*synx)); + max_synx = SYNC_INITIAL_CHUNK; + synx = nasm_malloc((max_synx + 1) * sizeof(*synx)); nsynx = 0; } void add_sync(uint32_t pos, uint32_t length) { - int i; + uint32_t i; if (nsynx >= max_synx) { - max_synx = (max_synx << 1) + 1; + if (max_synx >= SYNC_MAX_SIZE) /* too many sync points! */ + return; + max_synx = (max_synx << 1); synx = nasm_realloc(synx, (max_synx + 1) * sizeof(*synx)); } @@ -95,7 +101,7 @@ void add_sync(uint32_t pos, uint32_t length) uint32_t next_sync(uint32_t position, uint32_t *length) { while (nsynx > 0 && synx[1].pos + synx[1].length <= position) { - int i, j; + uint32_t i, j; swap_sync(nsynx, 1); nsynx--; |