Skip to content

Commit 336fce8

Browse files
committed
add malloc error
1 parent 5519b19 commit 336fce8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/forder.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ void radix_i(int from, int to, int radix) {
942942
push(&my_n, 1);
943943
TEND(5);
944944
continue;
945+
} else if (my_n < 1) {
946+
// do not sort for my_n < 1 since we do not cater for this later
947+
continue;
945948
}
946949
else if (my_n<=256) {
947950
// if nth==1
@@ -955,8 +958,10 @@ void radix_i(int from, int to, int radix) {
955958

956959
uint8_t *restrict my_key = key[radix]+from; // safe to write as we don't use this radix again
957960
uint8_t *o = (uint8_t *)malloc(my_n * sizeof(uint8_t));
958-
if (!o)
961+
if (!o) {
962+
free(queue);
959963
STOP(_("Failed to allocate %zu bytes for '%s'."), my_n * sizeof(uint8_t), "o"); // # nocov
964+
}
960965
// if last key (i.e. radix+1==nradix) there are no more keys to reorder so we could reorder osub by reference directly and save allocating and populating o just
961966
// to use it once. However, o's type is uint8_t so many moves within this max-256 vector should be faster than many moves in osub (4 byte or 8 byte ints) [1 byte
962967
// type is always aligned]

0 commit comments

Comments
 (0)