diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-11-04 19:14:47 +0700 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-11-04 19:14:47 +0700 |
commit | e26a6b81a2b489a177e5916c54a3a9c59edd3a12 (patch) | |
tree | f26860193dfc5f62ecc3667b1c78c601b3410c9a | |
parent | ae0444f94e25cfc8080eea4bcf9a5eadcc996a23 (diff) |
Test the bsearch result first
and only get content when pointer isn't NULL
-rw-r--r-- | client.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -80,9 +80,11 @@ void icclient_order(icclient_ord_order **orderptr, const char *sku qsort(items, order->nitems, sizeof(icclient_ord_item *), itemcmp); icclient_ord_item *key_item = malloc(sizeof(icclient_ord_item)); key_item->product = product; - item = *(icclient_ord_item **)bsearch(&key_item, items + icclient_ord_item **itemptr = bsearch(&key_item, items , order->nitems, sizeof(icclient_ord_item *) , itemcmp); + if (itemptr) + item = *itemptr; free(key_item); } else { *orderptr = malloc(sizeof(icclient_ord_order)); |