# HG changeset patch # User Josef 'Jeff' Sipek # Date 1551031968 18000 # Node ID 5c64f103bcefd537a3fe2eeecd69b437afff884c # Parent 94be6289538bcef4092038592d4bce52daa6aad7 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 diff -r 94be6289538b -r 5c64f103bcef sexpr.c --- 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; } /*