From 423b7a6d43efb07cd0124eb349f43ae7c7e04459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Tue, 13 Jul 2021 18:41:04 +0800 Subject: Anticipate empty services array There might be cases where there is the JSON object "services", there's the array, but it's empty. --- pikul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index 8e657b8..1ccf717 100644 --- a/pikul.c +++ b/pikul.c @@ -92,7 +92,7 @@ static int servicecmp(const void *service1, const void *service2) double pikul_cost(const char *origin, const char *destination, double weight, const char *code) { struct pikul_services *services = pikul_services(origin, destination, weight); - if (!services) + if (!services || !services->length) return .0; qsort(services->list, services->length, sizeof(struct pikul_service *), servicecmp); struct pikul_service *key_service = malloc(sizeof(struct pikul_service)); -- cgit v1.2.3