summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2020-06-24 13:41:15 +0300
committerAndes <uboot@andestech.com>2020-07-01 10:01:21 +0300
commit60ffcf218fb2ed73dac1bd44ef0d45661b7577db (patch)
tree23f672eb7d4c63c8e7be92689dee4256a5829cec /lib
parent038b13ee8134ba755a323732f3b2b838b9dc17a4 (diff)
downloadu-boot-60ffcf218fb2ed73dac1bd44ef0d45661b7577db.tar.xz
lib: Always set errno in hcreate_r
This could give a confusing error message if it failed and didn't set errno. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/hashtable.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/hashtable.c b/lib/hashtable.c
index b96dbe19be..7b6781bc35 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -110,8 +110,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 */
@@ -124,8 +126,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;