summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-13 18:41:04 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-13 18:41:04 +0800
commit423b7a6d43efb07cd0124eb349f43ae7c7e04459 (patch)
tree39f1c74d52c5773735b65f9b8aa39887117a4b2e
parent1432293735a0a8e480939816c26b20335d636a42 (diff)
Anticipate empty services array
There might be cases where there is the JSON object "services", there's the array, but it's empty.
-rw-r--r--pikul.c2
1 files changed, 1 insertions, 1 deletions
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));