mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2025-04-27 06:37:31 +00:00
Fix handling of large strings in strncat.
There were two issues: *If bit 15 of the n value was set, the second string would not be copied. *If the length of the second string was 64K or more, it would not be copied properly because the pointers were not updated. This test program demonstrates both issues: #pragma memorymodel 1 #include <stdlib.h> #include <string.h> #include <stdio.h> #define LEN2 100000 int main(void) { char *s1 = malloc(LEN2+2); char *s2 = malloc(LEN2+1); if (!s1 || !s2) return 0; for (unsigned long i = 0; i < LEN2; i++) s2[i] = '0' + (i & 0x07); strcpy(s1,"a"); strncat(s1, s2, LEN2); puts(s1); printf("len = %zu\n", strlen(s1)); }
This commit is contained in:
parent
b60c307ee6
commit
f1582be5a2
@ -1021,12 +1021,14 @@ lb2a short M copy characters 'til the null is found
|
||||
ldy #0
|
||||
ldx n
|
||||
beq lb4
|
||||
bmi lb4
|
||||
lb3 lda [s2],Y
|
||||
sta [s1],Y
|
||||
beq lb4
|
||||
iny
|
||||
dex
|
||||
bne lb3a
|
||||
inc s1+2
|
||||
inc s2+2
|
||||
lb3a dex
|
||||
bne lb3
|
||||
lda n+2
|
||||
beq lb4
|
||||
|
Loading…
x
Reference in New Issue
Block a user