summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-11-04 19:14:47 +0700
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-11-04 19:14:47 +0700
commite26a6b81a2b489a177e5916c54a3a9c59edd3a12 (patch)
treef26860193dfc5f62ecc3667b1c78c601b3410c9a
parentae0444f94e25cfc8080eea4bcf9a5eadcc996a23 (diff)
Test the bsearch result first
and only get content when pointer isn't NULL
-rw-r--r--client.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/client.c b/client.c
index 641db88..d60c8e1 100644
--- a/client.c
+++ b/client.c
@@ -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));