In qsort, make sure to do nothing if count is 0.

Previously, it could behave incorrectly in some cases where count was 0. This would happen if the address calculation &base[-1] wrapped around and produced a large number, either because base was NULL or because size was larger than the address of base.

This fixes #33.
This commit is contained in:
Stephen Heumann 2021-02-25 22:52:34 -06:00
parent 9af245933c
commit 7e95f8b182
1 changed files with 4 additions and 1 deletions

View File

@ -663,6 +663,9 @@ qsort start
phk
plb
lda count nothing to do if count is 0
ora count+2
beq done
dec4 count set count to the addr of the last entry
mul4 count,size
add4 count,base
@ -677,7 +680,7 @@ qsort start
ph4 base
jsl rsort
plb
done plb
creturn
end