diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2021-03-16 17:48:43 +0000 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2021-03-16 17:54:12 +0000 |
commit | 2ffc5656bc08d51f56363b62d2ce9d9737678451 (patch) | |
tree | 11d70c0fc6db24d0ee97fe8bfdb5c283ee0c51a3 | |
parent | 29e88ec91d42f21b90ce5fe08c3a66e74d7dfe97 (diff) | |
download | ghostpdl-2ffc5656bc08d51f56363b62d2ce9d9737678451.tar.gz |
Rejig clist_mutate_to_clist for Coverity.
Coverity spotted us accessing *the_memory without having checked
that the_memory != NULL first.
In fixing that, I've taken the chance to tidy up the function a bit.
-rw-r--r-- | base/gxclist.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/base/gxclist.c b/base/gxclist.c index f6a8a3201..7c7f0aa46 100644 --- a/base/gxclist.c +++ b/base/gxclist.c @@ -1516,19 +1516,27 @@ BACKTRACE(pdev); "cmd list buffer") : gs_alloc_bytes(buffer_memory, space, "cmd list buffer")); - if (base != 0) - break; - if (bufferSpace_is_exact || (space >>= 1) < min_buffer_space) + if (base != NULL) + break; /* Allocation worked! Stop trying. */ + if (bufferSpace_is_exact) { + /* We wanted a specific size. Accept no substitutes. */ break; + } + /* Let's try again for half the size. */ + if (space == min_buffer_space) + break; /* We already failed at the minimum size. */ + space >>= 1; + if (space < min_buffer_space) + space = min_buffer_space; } - if (base == 0) + if (base == NULL) return_error(gs_error_VMerror); - if (the_memory) - *the_memory = base; /* Try opening the command list, to see if we allocated */ /* enough buffer space. */ open_c: + if (the_memory) + *the_memory = base; pdev->buf = base; pdev->buffer_space = space; pclist_dev->common.orig_spec_op = dev_spec_op; @@ -1555,17 +1563,15 @@ open_c: base = gs_resize_object(buffer_memory, *the_memory, space, "cmd list buf(retry open)"); - if (base != 0) - *the_memory = base; } else { gs_free_object(buffer_memory, base, "cmd list buf(retry open)"); - *the_memory = base = - gs_alloc_bytes(buffer_memory, space, - "cmd list buf(retry open)"); + base = gs_alloc_bytes(buffer_memory, space, + "cmd list buf(retry open)"); + if (the_memory != NULL) + *the_memory = base; } - pdev->buf = *the_memory; - if (base != 0) { + if (base != NULL) { pdev->is_open = save_is_open; /* allow for success when we loop */ goto open_c; } @@ -1574,7 +1580,9 @@ open_c: if (!reallocate) { gs_free_object(buffer_memory, base, "cmd list buf"); pdev->buffer_space = 0; - *the_memory = NULL; + if (the_memory != NULL) + *the_memory = NULL; + pdev->buf = NULL; } } return code; |