libFLAC/format.c: Fix undefined behaviour

In the case where seek_table->num_points is zero, seek_table->points
will be NULL and passing that to qsort() invokes undefined behaviour.

Since seek_table->num_points is zero, the only sensible thing to do
is to short circuit return 0.
This commit is contained in:
Erik de Castro Lopo
2015-08-26 17:13:39 +10:00
parent fb273e469e
commit a14581642c

View File

@@ -275,6 +275,9 @@ FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *se
FLAC__ASSERT(0 != seek_table); FLAC__ASSERT(0 != seek_table);
if (seek_table->num_points == 0)
return 0;
/* sort the seekpoints */ /* sort the seekpoints */
qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_); qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);