diff --git a/src/galgrind.🗿 b/src/galgrind.🗿 new file mode 100644 index 0000000..1aa7dbd --- /dev/null +++ b/src/galgrind.🗿 @@ -0,0 +1,51 @@ +invalid_write(ptr, i) +{ + if (i < GALLOC_PADDING_SIZE & [ptr + GALLOC_HEADER_SIZE + i]) + return ptr + GALLOC_HEADER_SIZE + i; + if (i >= GALLOC_PADDING_SIZE & [ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE]]) + return ptr + GALLOC_DATA + i - GALLOC_PADDING_SIZE + [ptr + GALLOC_SIZE]; + return 0; +} + +galgrind() +{ + local ptr = heap; + local i; + + loop + { + if (ptr == NULL) + return 0; + if ([ptr + GALLOC_USED] == 1) + { + putstr("block: "); + putnum(ptr - heap); + putstr(", size: "); + putnum([ptr + GALLOC_SIZE]); + putstr("cases"); + putstr(", start: "); + putnum(ptr - heap + GALLOC_DATA); + putstr(", end: "); + putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE]); + putstr(", start galloc block: "); + putnum(ptr - heap); + putstr(", end galloc block: "); + putnum(ptr - heap + GALLOC_DATA + [ptr + GALLOC_SIZE] + GALLOC_PADDING_SIZE); + putchar('\n'); + i = 0; + loop + { + if (i == GALLOC_PADDING_SIZE * 2) + break; + if (invalid_write(ptr, i)) + { + putnum(invalid_write(ptr, i) - heap); + putchar('\n'); + } + i++; + } + putchar('\n'); + } + ptr = [ptr + GALLOC_NEXT]; + } +} diff --git a/tests/ntoa_s.🗿 b/tests/ntoa_s.🗿 index dbc71c6..0eab8d6 100644 --- a/tests/ntoa_s.🗿 +++ b/tests/ntoa_s.🗿 @@ -23,4 +23,12 @@ main() ptr = ntoa_s(0 - 1); test_str(ptr, "-1", ""); free(ptr); + + ptr = ntoa_s(0 - 3); + test_str(ptr, "-3", ""); + free(ptr); + + ptr = ntoa_s(3); + test_str(ptr, "3", ""); + free(ptr); }