From b60c307ee6b90c4fcd5e9090e8c50952aa26377d Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 18 Feb 2024 21:01:01 -0600 Subject: [PATCH] Make strcat and strncat work properly when first string crosses a bank boundary. Previously, the pointer was not properly updated to account for the bank crossing, so the characters from the second string would be written to the wrong bank. Here is an example that illustrates this: #include #include #include #include int main(void) { Handle hndl = NewHandle(0x1000f, userid(), 0xC000, 0); if (toolerror()) return 0; char *s = *hndl; s = (void*)((unsigned long)s | 0xffff); strcpy(s, "foo"); strcat(s, "bar"); strncat(s, "baz", 5); puts(s); } --- string.asm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/string.asm b/string.asm index e5cd5ae..6a06be5 100644 --- a/string.asm +++ b/string.asm @@ -616,7 +616,9 @@ lb2 long M clc adc s1 sta s1 - short M copy characters 'til the null is found + bcc lb2a + inc s1+2 +lb2a short M copy characters 'til the null is found ldy #0 lb3 lda [s2],Y sta [s1],Y @@ -1013,7 +1015,9 @@ lb2 long M clc adc s1 sta s1 - short M copy characters 'til the null is found + bcc lb2a + inc s1+2 +lb2a short M copy characters 'til the null is found ldy #0 ldx n beq lb4