From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Anderson Date: Wed, 22 Apr 2020 22:33:10 -0400 Subject: [PATCH v9 11/21] lib: Always set errno in hcreate_r In-Reply-To: <20200423023320.1380090-1-seanga2@gmail.com> References: <20200423023320.1380090-1-seanga2@gmail.com> Message-ID: <20200423023320.1380090-12-seanga2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This could give a confusing error message if it failed and didn't set errno. Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- Changes in v5: - New lib/hashtable.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/hashtable.c b/lib/hashtable.c index 907e8a642f..e9ac7e252e 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -109,8 +109,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab) } /* There is still another table active. Return with error. */ - if (htab->table != NULL) + if (htab->table != NULL) { + __set_errno(EINVAL); return 0; + } /* Change nel to the first prime number not smaller as nel. */ nel |= 1; /* make odd */ @@ -123,8 +125,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab) /* allocate memory and zero out */ htab->table = (struct env_entry_node *)calloc(htab->size + 1, sizeof(struct env_entry_node)); - if (htab->table == NULL) + if (htab->table == NULL) { + __set_errno(ENOMEM); return 0; + } /* everything went alright */ return 1; -- 2.25.1