diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2020-02-06 15:08:55 +0000 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2020-02-06 15:57:12 +0000 |
commit | e193b5dc14a6029b2648a5712c154499d819186f (patch) | |
tree | 2d9d62851bab2033904dc3ceef58d324f2808a9c | |
parent | 3ac7d3c0ed5a339c8e2fe25c43feac92b9813b1b (diff) | |
download | ghostpdl-e193b5dc14a6029b2648a5712c154499d819186f.tar.gz |
Bug 702100: Fix memory limit to be based on size_t not long.
I missed this when converting from longs to size_ts. This
resulted on different maximums for linux and windows 64bit
builds, due to the different size of longs on those two
platforms.
Update the debugging printfs to make use of the PRIdSIZE macros
rather than truncating.
-rw-r--r-- | base/gsalloc.c | 24 | ||||
-rw-r--r-- | base/gsmalloc.c | 4 | ||||
-rw-r--r-- | base/std.h | 1 |
3 files changed, 15 insertions, 14 deletions
diff --git a/base/gsalloc.c b/base/gsalloc.c index 89fb91e7c..c9c3ba0eb 100644 --- a/base/gsalloc.c +++ b/base/gsalloc.c @@ -865,8 +865,8 @@ ialloc_add_clump(gs_ref_memory_t *imem, ulong space, client_name_t cname) /* Allow acquisition of this clump. */ imem->is_controlled = false; imem->large_size = imem->clump_size; - imem->limit = max_long; - imem->gc_status.max_vm = max_long; + imem->limit = max_size_t; + imem->gc_status.max_vm = max_size_t; /* Acquire the clump. */ cp = alloc_add_clump(imem, space, cname); @@ -960,7 +960,7 @@ ialloc_set_limit(register gs_ref_memory_t * mem) 0); if (mem->gc_status.enabled) { - ulong limit = mem->gc_allocated + mem->gc_status.vm_threshold; + size_t limit = mem->gc_allocated + mem->gc_status.vm_threshold; if (limit < mem->previous_status.allocated) mem->limit = 0; @@ -971,12 +971,12 @@ ialloc_set_limit(register gs_ref_memory_t * mem) } else mem->limit = min(max_allocated, mem->gc_allocated + FORCE_GC_LIMIT); if_debug7m('0', (const gs_memory_t *)mem, - "[0]space=%d, max_vm=%ld, prev.alloc=%ld, enabled=%d, " - "gc_alloc=%ld, threshold=%ld => limit=%ld\n", - mem->space, (long)mem->gc_status.max_vm, - (long)mem->previous_status.allocated, - mem->gc_status.enabled, (long)mem->gc_allocated, - (long)mem->gc_status.vm_threshold, (long)mem->limit); + "[0]space=%d, max_vm=%"PRIdSIZE", prev.alloc=%"PRIdSIZE", enabled=%d, " + "gc_alloc=%"PRIdSIZE", threshold=%"PRIdSIZE" => limit=%"PRIdSIZE"\n", + mem->space, mem->gc_status.max_vm, + mem->previous_status.allocated, + mem->gc_status.enabled, mem->gc_allocated, + mem->gc_status.vm_threshold, mem->limit); } struct free_data @@ -2476,9 +2476,9 @@ alloc_acquire_clump(gs_ref_memory_t * mem, size_t csize, bool has_strings, return 0; } if_debug4m('0', (const gs_memory_t *)mem, - "[0]signaling space=%d, allocated=%ld, limit=%ld, requested=%ld\n", - mem->space, (long)mem->allocated, - (long)mem->limit, (long)mem->gc_status.requested); + "[0]signaling space=%d, allocated=%"PRIdSIZE", limit=%"PRIdSIZE", requested=%"PRIdSIZE"\n", + mem->space, mem->allocated, + mem->limit, mem->gc_status.requested); mem->gs_lib_ctx->gcsignal = mem->gc_status.signal_value; } } diff --git a/base/gsmalloc.c b/base/gsmalloc.c index 52998b17e..971976a07 100644 --- a/base/gsmalloc.c +++ b/base/gsmalloc.c @@ -119,7 +119,7 @@ gs_malloc_memory_init(void) mem->stable_memory = 0; /* just for tidyness, never referenced */ mem->procs = gs_malloc_memory_procs; mem->allocated = 0; - mem->limit = max_long; + mem->limit = max_size_t; mem->used = 0; mem->max_used = 0; mem->gs_lib_ctx = 0; @@ -186,7 +186,7 @@ gs_heap_alloc_bytes(gs_memory_t * mem, size_t size, client_name_t cname) } else { size_t added = size + sizeof(gs_malloc_block_t); - if (added <= size || mmem->limit - added < mmem->used) + if (added <= size || added > mmem->limit || mmem->limit - added < mmem->used) set_msg("exceeded limit"); else if ((ptr = (byte *) Memento_label(malloc(added), cname)) == 0) set_msg("failed"); diff --git a/base/std.h b/base/std.h index 4f91777b9..9c9e817f1 100644 --- a/base/std.h +++ b/base/std.h @@ -85,6 +85,7 @@ typedef ulong bits32; #define max_ushort ARCH_MAX_USHORT #define max_uint ARCH_MAX_UINT #define max_ulong ARCH_MAX_ULONG +#define max_size_t ARCH_MAX_SIZE_T /* Minimum and maximum values for pointers. */ #if ARCH_PTRS_ARE_SIGNED |