From cdb62825a3a4d0ac042848b24ed121d58643f524 Mon Sep 17 00:00:00 2001 From: ymdatta Date: Thu, 29 Aug 2024 23:08:54 -0400 Subject: [PATCH] v.external.out: Check for valid array before passing it to qsort (#4251) Currently, if 'HAVE_OGR' macro is defined, as part of execution, we sort all formats by name using qsort. But, array containing all formats is assigned based on a conditional and if the conditional fails, it can be NULL. Behavior of qsort when a NULL array is provided is undefined. To avoid getting into that situation, check if the array is NULL before performing qsort on it. Signed-off-by: Mohan Yelugoti --- vector/v.external.out/list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/v.external.out/list.c b/vector/v.external.out/list.c index 56ec201a3e9..708d2795e76 100644 --- a/vector/v.external.out/list.c +++ b/vector/v.external.out/list.c @@ -53,7 +53,8 @@ char **format_list(int *count, size_t *len) } /* order formats by name */ - qsort(list, *count, sizeof(char *), cmp); + if (list) + qsort(list, *count, sizeof(char *), cmp); #endif #if defined HAVE_POSTGRES && !defined HAVE_OGR list = G_realloc(list, ((*count) + 1) * sizeof(char *));