From 7e95f8b182b9723590ffae123809e0d783ef5f05 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 25 Feb 2021 22:52:34 -0600 Subject: [PATCH] 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. --- stdlib.asm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib.asm b/stdlib.asm index fd9e04b..05847e5 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -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