Mercurial > libjeffpc
changeset 820:fcbf39e8ae4e
nvl_alloc returns a negated errno on error
Checking for NULL is useless since nvl_alloc never returns NULL.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 12 Oct 2020 11:46:59 -0400 |
parents | 616a36d39703 |
children | cbde4a6170af |
files | scgisvc.c tests/test_nvl.c tests/test_nvl_pack.c tests/test_qstring.c |
diffstat | 4 files changed, 27 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/scgisvc.c Sun Sep 06 23:28:12 2020 -0400 +++ b/scgisvc.c Mon Oct 12 11:46:59 2020 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2014-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -322,9 +322,18 @@ req->response.bodylen = 0; req->response.body = NULL; - if (!req->request.headers || !req->request.query || - !req->response.headers) { - ret = -ENOMEM; + if (IS_ERR(req->request.headers)) { + ret = PTR_ERR(req->request.headers); + goto err; + } + + if (IS_ERR(req->request.query)) { + ret = PTR_ERR(req->request.query); + goto err; + } + + if (IS_ERR(req->response.headers)) { + ret = PTR_ERR(req->response.headers); goto err; } @@ -346,9 +355,12 @@ if (!init_failed && req->ops->deinit) req->ops->deinit(req); - nvl_putref(req->request.headers); - nvl_putref(req->request.query); - nvl_putref(req->response.headers); + if (!IS_ERR(req->request.headers)) + nvl_putref(req->request.headers); + if (!IS_ERR(req->request.query)) + nvl_putref(req->request.query); + if (!IS_ERR(req->response.headers)) + nvl_putref(req->response.headers); /* NOTE: Do *not* close the fd, it'll be closed by socksvc */
--- a/tests/test_nvl.c Sun Sep 06 23:28:12 2020 -0400 +++ b/tests/test_nvl.c Mon Oct 12 11:46:59 2020 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2017-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,8 +29,8 @@ struct nvlist *nvl; nvl = nvl_alloc(); - if (!nvl) - fail("nvl_alloc() failed"); + if (IS_ERR(nvl)) + fail("nvl_alloc() failed: %s", xstrerror(PTR_ERR(nvl))); return nvl; }
--- a/tests/test_nvl_pack.c Sun Sep 06 23:28:12 2020 -0400 +++ b/tests/test_nvl_pack.c Mon Oct 12 11:46:59 2020 -0400 @@ -33,8 +33,8 @@ struct nvlist *nvl; nvl = nvl_alloc(); - if (!nvl) - fail("nvl_alloc() failed"); + if (IS_ERR(nvl)) + fail("nvl_alloc() failed: %s", xstrerror(PTR_ERR(nvl))); return nvl; }
--- a/tests/test_qstring.c Sun Sep 06 23:28:12 2020 -0400 +++ b/tests/test_qstring.c Mon Oct 12 11:46:59 2020 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2014-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -34,8 +34,8 @@ int ret; vars = nvl_alloc(); - if (!vars) - return -ENOMEM; + if (IS_ERR(vars)) + return PTR_ERR(vars); ret = qstring_parse_len(vars, ibuf, len); if (!ret) {