Mercurial > libjeffpc
changeset 678:5c64f103bcef
sexpr: return negated errnos on list to array conversion failures
This way, we can differentiate if the failure was because of not enough
memory or if the input value was not a list.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sun, 24 Feb 2019 13:12:48 -0500 |
parents | 94be6289538b |
children | 8a52160595a1 |
files | sexpr.c |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/sexpr.c Sun Feb 24 13:11:11 2019 -0500 +++ b/sexpr.c Sun Feb 24 13:12:48 2019 -0500 @@ -109,18 +109,23 @@ { struct val *tmp; size_t nvals = 0; + ssize_t ret; for (tmp = list; !sexpr_is_null(tmp) && (alen > nvals); tmp = tmp->cons.tail, nvals++) { - if (tmp->type != VT_CONS) + if (tmp->type != VT_CONS) { + ret = -EINVAL; goto err; + } array[nvals] = val_getref(tmp->cons.head); } - if ((alen == nvals) && !sexpr_is_null(tmp)) + if ((alen == nvals) && !sexpr_is_null(tmp)) { + ret = -ENOMEM; goto err; + } return nvals; @@ -128,7 +133,7 @@ while (nvals) val_putref(array[--nvals]); - return -1; + return ret; } /*