From ca815af0775b89cfdb97957c69685157eacdbe51 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 8 Jun 2000 18:35:04 +0000 Subject: [PATCH] iscntrl was not mentioned in the Makefile and therefor not built. Change the isxxx functions to correctly handle values outside of character range. git-svn-id: svn://svn.cc65.org/cc65/trunk@33 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/Makefile | 2 +- libsrc/common/_hadd.c | 5 +++-- libsrc/common/isalnum.s | 6 ++++++ libsrc/common/isalpha.s | 6 ++++++ libsrc/common/isblank.s | 6 ++++++ libsrc/common/iscntrl.s | 5 +++++ libsrc/common/isdigit.s | 6 ++++++ libsrc/common/isgraph.s | 6 ++++++ libsrc/common/islower.s | 6 ++++++ libsrc/common/isprint.s | 6 ++++++ libsrc/common/ispunct.s | 6 ++++++ libsrc/common/isspace.s | 6 ++++++ libsrc/common/isupper.s | 6 ++++++ libsrc/common/isxdigit.s | 6 ++++++ libsrc/common/malloc.c | 33 +++++++++------------------------ 15 files changed, 84 insertions(+), 27 deletions(-) diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index 2bbeede0b..fe1f6edbb 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -28,7 +28,7 @@ S_OBJS = isalpha.o isdigit.o _file.o fmisc.o strlower.o strchr.o tolower.o\ longjmp.o rand.o atexit.o memset.o memcpy.o memchr.o memcmp.o\ ltoa.o strcspn.o strncat.o strpbrk.o strspn.o abs.o labs.o jmpvec.o\ _fdesc.o stkcheck.o zerobss.o copydata.o _swap.o strstr.o strcoll.o\ - _sys.o getcpu.o _oserror.o strerror.o + _sys.o getcpu.o _oserror.o strerror.o iscntrl.o all: $(C_OBJS) $(S_OBJS) diff --git a/libsrc/common/_hadd.c b/libsrc/common/_hadd.c index 190875d64..c257ffcdf 100644 --- a/libsrc/common/_hadd.c +++ b/libsrc/common/_hadd.c @@ -58,7 +58,7 @@ void _hadd (void* mem, size_t size) */ if (right) { /* Check if we must merge the block with the right one */ - if (((int) f) + size == (int) right) { + if (((unsigned) f) + size == (unsigned) right) { /* Merge with the right block */ f->size += right->size; if (f->next = right->next) { @@ -79,7 +79,7 @@ void _hadd (void* mem, size_t size) } if (left) { /* Check if we must merge the block with the left one */ - if ((int) f == ((int) left) + left->size) { + if ((unsigned) f == ((unsigned) left) + left->size) { /* Merge with the left block */ left->size += f->size; if (left->next = f->next) { @@ -104,3 +104,4 @@ void _hadd (void* mem, size_t size) + diff --git a/libsrc/common/isalnum.s b/libsrc/common/isalnum.s index e8654ad9f..8c29964ed 100644 --- a/libsrc/common/isalnum.s +++ b/libsrc/common/isalnum.s @@ -8,8 +8,14 @@ .import __ctype _isalnum: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$07 ; Mask character/digit bits rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isalpha.s b/libsrc/common/isalpha.s index 420d6b3dc..d0fcf97b2 100644 --- a/libsrc/common/isalpha.s +++ b/libsrc/common/isalpha.s @@ -8,8 +8,14 @@ .import __ctype _isalpha: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$03 ; Mask character bits rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isblank.s b/libsrc/common/isblank.s index f3564ec63..5568a547d 100644 --- a/libsrc/common/isblank.s +++ b/libsrc/common/isblank.s @@ -10,8 +10,14 @@ .import __ctype _isblank: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$80 ; Mask blank bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/iscntrl.s b/libsrc/common/iscntrl.s index 6d29cb586..55307bd5a 100644 --- a/libsrc/common/iscntrl.s +++ b/libsrc/common/iscntrl.s @@ -8,9 +8,14 @@ .import __ctype _iscntrl: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$10 ; Mask control character bit rts +@L1: lda #$00 ; Return false + tax + rts diff --git a/libsrc/common/isdigit.s b/libsrc/common/isdigit.s index d8cc6d522..b0608ba72 100644 --- a/libsrc/common/isdigit.s +++ b/libsrc/common/isdigit.s @@ -8,8 +8,14 @@ .import __ctype _isdigit: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$04 ; Mask digit bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isgraph.s b/libsrc/common/isgraph.s index 91f482c56..e2073aea2 100644 --- a/libsrc/common/isgraph.s +++ b/libsrc/common/isgraph.s @@ -8,9 +8,15 @@ .import __ctype _isgraph: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification eor #$30 ; NOT control and NOT space and #$30 ; Mask character bits rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/islower.s b/libsrc/common/islower.s index 565f0f853..c8b131600 100644 --- a/libsrc/common/islower.s +++ b/libsrc/common/islower.s @@ -8,8 +8,14 @@ .import __ctype _islower: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$01 ; Mask lower char bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isprint.s b/libsrc/common/isprint.s index e82e61312..37657df92 100644 --- a/libsrc/common/isprint.s +++ b/libsrc/common/isprint.s @@ -8,9 +8,15 @@ .import __ctype _isprint: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification eor #$10 ; NOT a control char and #$10 ; Mask control char bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/ispunct.s b/libsrc/common/ispunct.s index 71664f0d8..c2d6c2338 100644 --- a/libsrc/common/ispunct.s +++ b/libsrc/common/ispunct.s @@ -8,9 +8,15 @@ .import __ctype _ispunct: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification eor #$37 ; NOT (space | control | digit | char) and #$37 ; Mask relevant bits rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isspace.s b/libsrc/common/isspace.s index 1c6cc2e8a..62be7d59e 100644 --- a/libsrc/common/isspace.s +++ b/libsrc/common/isspace.s @@ -8,8 +8,14 @@ .import __ctype _isspace: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$60 ; Mask space bits rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isupper.s b/libsrc/common/isupper.s index bb5ad07a2..0eb4915c6 100644 --- a/libsrc/common/isupper.s +++ b/libsrc/common/isupper.s @@ -8,8 +8,14 @@ .import __ctype _isupper: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$02 ; Mask upper char bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/isxdigit.s b/libsrc/common/isxdigit.s index a3184d17b..91b041ca7 100644 --- a/libsrc/common/isxdigit.s +++ b/libsrc/common/isxdigit.s @@ -8,8 +8,14 @@ .import __ctype _isxdigit: + cpx #$00 ; Char range ok? + bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification and #$08 ; Mask xdigit bit rts +@L1: lda #$00 ; Return false + tax + rts + diff --git a/libsrc/common/malloc.c b/libsrc/common/malloc.c index d7722d595..ca4044c47 100644 --- a/libsrc/common/malloc.c +++ b/libsrc/common/malloc.c @@ -69,34 +69,19 @@ void* malloc (size_t size) } else { - /* We must slice the block found */ - struct freeblock* newblock; - newblock = (struct freeblock*) ((unsigned) f) + size; + /* We must slice the block found. Cut off space from the upper + * end, so we can leave the actual free block chain intact. + */ - /* Insert the new block (the remaining space) instead of the - * old one. - */ - newblock->size = f->size - size; /* Remaining size */ - newblock->next = f->next; - newblock->prev = f->prev; - if (f->prev) { - /* We have a previous block */ - f->prev->next = newblock; - } else { - /* This is the first block, correct the freelist pointer */ - _hfirst = newblock; - } - if (f->next) { - /* We have a next block */ - f->next->prev = newblock; - } else { - /* This is the last block, correct the freelist pointer */ - _hlast = newblock; - } + /* Decrement the size of the block */ + f->size -= size; + + /* Set f to the now unused space above the current block */ + f = (struct freeblock*) (((unsigned) f) + f->size); } - /* Setup the pointer for the bock */ + /* Setup the pointer for the block */ p = (unsigned*) f; } else {