diff options
author | Gert Wollny <[email protected]> | 2018-09-04 09:36:53 +0200 |
---|---|---|
committer | Gert Wollny <[email protected]> | 2018-09-05 13:54:01 +0200 |
commit | 218ff0d5105fe5d8d77e890d213de972980bd510 (patch) | |
tree | fb347d2fb706e48458deb4c83636fae3be3f417f /src | |
parent | 5341260f62b66f8b8e503d7c8aff5703629193f0 (diff) |
winsys/virgl/vtest: Correct off-by-one error in resource allocation
The resource bo array must already extended when the target index is
equal to the current size of the array.
Signed-off-by: Gert Wollny <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c index 9a96c6eb83f..6c03a6b3594 100644 --- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c +++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c @@ -459,13 +459,18 @@ static void virgl_vtest_add_res(struct virgl_vtest_winsys *vtws, { unsigned hash = res->res_handle & (sizeof(cbuf->is_handle_added)-1); - if (cbuf->cres > cbuf->nres) { - cbuf->nres += 256; - cbuf->res_bo = realloc(cbuf->res_bo, cbuf->nres * sizeof(struct virgl_hw_buf*)); - if (!cbuf->res_bo) { + if (cbuf->cres >= cbuf->nres) { + unsigned new_nres = cbuf->nres + 256; + struct virgl_hw_res **new_re_bo = REALLOC(cbuf->res_bo, + cbuf->nres * sizeof(struct virgl_hw_buf*), + new_nres * sizeof(struct virgl_hw_buf*)); + if (!new_re_bo) { fprintf(stderr,"failure to add relocation %d, %d\n", cbuf->cres, cbuf->nres); return; } + + cbuf->res_bo = new_re_bo; + cbuf->nres = new_nres; } cbuf->res_bo[cbuf->cres] = NULL; |