add: positive num test to ntoa_s

This commit is contained in:
starnakin 2023-07-26 23:35:52 +02:00
parent 21c78421a4
commit e417a01f9a
2 changed files with 59 additions and 0 deletions

51
src/galgrind.🗿 Normal file
View File

@ -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];
}
}

View File

@ -23,4 +23,12 @@ main()
ptr = ntoa_s(0 - 1); ptr = ntoa_s(0 - 1);
test_str(ptr, "-1", ""); test_str(ptr, "-1", "");
free(ptr); free(ptr);
ptr = ntoa_s(0 - 3);
test_str(ptr, "-3", "");
free(ptr);
ptr = ntoa_s(3);
test_str(ptr, "3", "");
free(ptr);
} }