diff options
author | Yann Ylavic <ylavic@apache.org> | 2021-03-11 14:12:19 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2021-03-11 14:12:19 +0000 |
commit | 6369bd1f7f6eed73c7f3385377ac8e9ffe4d34cd (patch) | |
tree | 89600ab09bfaed1684604b1c6de26b8aef16a3a3 | |
parent | a15958a37a06f71c42c690278f9c958b93b7ee20 (diff) | |
download | apr-6369bd1f7f6eed73c7f3385377ac8e9ffe4d34cd.tar.gz |
Merge r1887481, r1887482 from trunk:
apr_skiplist: Handle ENOMEM from skiplisti_init(), fixing a compiler warning.
gcc-10 raises:
tables/apr_skiplist.c: In function ‘apr_skiplist_add_index’:
tables/apr_skiplist.c:284:16: error: ‘ni’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
284 | nsln = apr_skiplist_insert(ni, m->data);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
because above skiplisti_init() might return with ENOMEM, leaving ni uninitialized.
Since apr_skiplist_add_index returns void, the only option is to abort() in
this case.
For apr_skiplist_init(), we can forward the APR_ENOMEM to the caller.
Follow up to r1887481: fix skiplisti_init() returned pointer.
Submitted by: ylavic
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1887486 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | tables/apr_skiplist.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tables/apr_skiplist.c b/tables/apr_skiplist.c index 5ea8643db..b11acad69 100644 --- a/tables/apr_skiplist.c +++ b/tables/apr_skiplist.c @@ -238,11 +238,20 @@ static int indexing_compk(void *ac, void *b) APR_DECLARE(apr_status_t) apr_skiplist_init(apr_skiplist **s, apr_pool_t *p) { + apr_status_t rv; apr_skiplist *sl; - skiplisti_init(s, p); - sl = *s; - skiplisti_init(&(sl->index), p); + rv = skiplisti_init(&sl, p); + if (rv != APR_SUCCESS) { + *s = NULL; + return rv; + } + rv = skiplisti_init(&sl->index, p); + if (rv != APR_SUCCESS) { + *s = NULL; + return rv; + } apr_skiplist_set_compare(sl->index, indexing_comp, indexing_compk); + *s = sl; return APR_SUCCESS; } @@ -270,7 +279,10 @@ APR_DECLARE(void) apr_skiplist_add_index(apr_skiplist *sl, if (m) { return; /* Index already there! */ } - skiplisti_init(&ni, sl->pool); + if (skiplisti_init(&ni, sl->pool) != APR_SUCCESS) { + abort(); + return; + } apr_skiplist_set_compare(ni, comp, compk); /* Build the new index... This can be expensive! */ m = apr_skiplist_insert(sl->index, ni); |