Skip to content

Commit

Permalink
v.external.out: Check for valid array before passing it to qsort (OSG…
Browse files Browse the repository at this point in the history
…eo#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 <ymdatta.work@gmail.com>
  • Loading branch information
ymdatta authored and a0x8o committed Sep 5, 2024
1 parent 83fef77 commit 99193e4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vector/v.external.out/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *));
Expand Down

0 comments on commit 99193e4

Please sign in to comment.