From 60d49c7dc3426f5690fcc495e16bcc88ecfef49b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 14 Feb 2023 18:43:40 -0600 Subject: [PATCH] Fix qsort code for swapping elements with a size of 64KiB or more. This code did not previously work properly, because the X register value was overwritten within the loop. This could result in incorrect behavior such as hanging or data corruption when using qsort with element sizes >= 64KiB. --- stdlib.asm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib.asm b/stdlib.asm index c790553..bcbe300 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -830,8 +830,9 @@ r equ 7 right entry swap tsc set up addressing phd tcd - ldx lsize+2 move 64K chunks + lda lsize+2 move 64K chunks beq sw2 + sta banks ldy #0 sw1 lda [l],Y tax @@ -844,7 +845,7 @@ sw1 lda [l],Y bne sw1 inc l+2 inc r+2 - dex + dec banks bne sw1 sw2 lda lsize if there are an odd number of bytes then lsr A @@ -893,6 +894,7 @@ sw6 pld ; lsize entry ds 4 local copy of size +banks ds 2 number of whole banks to swap end ****************************************************************