Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/libc/memrchr.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
public _memrchr

_memrchr:
ld iy, 0
ld iy, -1
add iy, sp
ld hl, (iy + 3)
ld bc, (iy + 9)
dec bc
ld bc, (iy + 10)
sbc hl, hl
add hl, bc
jr c, .ret_zero
inc bc
ld a, (iy + 6)
jr nc, .ret_zero
ld de, (iy + 4)
add hl, de
ld a, (iy + 7)
cpdr
inc hl
ret z ; found match
; or a, a ; carry won't be set unless (ptr + size) wraps-around (which is UB)
.ret_zero:
; return NULL
or a, a
sbc hl, hl
ret
7 changes: 7 additions & 0 deletions test/standalone/asprintf_fprintf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#define SINK (char*)0xE40000

/* pass NULL into functions without triggering -Wnonnull */
extern void* NULL_ptr;

// prevents Clang from replacing function calls with builtins
#if 1

Expand Down Expand Up @@ -543,6 +546,9 @@ int strncmp_test(void) {
}

int memrchr_test(void) {
C(T_memrchr(NULL_ptr, 0x00, 0) == NULL_ptr);
C(T_memrchr(NULL_ptr, 0xFF, 0) == NULL_ptr);

C(T_memrchr(SINK, 0x00, 0) == NULL);
C(T_memrchr(SINK, 0x00, 1) == SINK);
C(T_memrchr(SINK, 0xFF, 1) == NULL);
Expand All @@ -565,6 +571,7 @@ int memrchr_test(void) {
C(T_memrchr(test, 'G', test_strlen) == NULL);
C(T_memrchr(test, 'G', test_size) == NULL);
C(T_memrchr(test0, 'G', sizeof(test0)) == test0);

return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions test/standalone/asprintf_fprintf/src/rename.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ _T_stpcpy := _stpcpy

_T_bzero := _bzero

section .rodata

public _NULL_ptr
_NULL_ptr:
db $00, $00, $00

extern _memset, _memcpy, _memcmp, _memccpy, _mempcpy, _memrchr
extern _strlen, _strcmp, _strncmp, _stpcpy
extern _bzero
Loading