From e26a6b81a2b489a177e5916c54a3a9c59edd3a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Mon, 4 Nov 2019 19:14:47 +0700 Subject: Test the bsearch result first and only get content when pointer isn't NULL --- client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)); -- cgit v1.2.3