mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 00:29:31 +00:00
3e01ac9b04
If user requests a size >= 65532, adding the heap admin size overflows size. Fixes #2358.
35 lines
871 B
C
35 lines
871 B
C
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "unittest.h"
|
|
|
|
TEST
|
|
{
|
|
char *buf, *buf2;
|
|
unsigned int i;
|
|
|
|
buf = malloc(0);
|
|
ASSERT_IsTrue (buf == NULL, "malloc (0) returned something");
|
|
|
|
for (i = 1; i < 10; i++) {
|
|
buf = malloc(i);
|
|
ASSERT_IsTrue (buf != NULL, "small returned nothing");
|
|
}
|
|
|
|
buf = malloc(4096);
|
|
ASSERT_IsTrue (buf != NULL, "malloc (4096) returned nothing");
|
|
|
|
buf = malloc(61000UL);
|
|
ASSERT_IsTrue (buf == NULL, "malloc (61000) returned something");
|
|
|
|
for (i = 65535UL; i > _heapmaxavail(); i--) {
|
|
buf = malloc(i);
|
|
ASSERT_IsTrue (buf == NULL, "malloc returned something but shouldn't have");
|
|
}
|
|
|
|
buf = malloc(i);
|
|
ASSERT_IsTrue (buf != NULL, "malloc returned nothing but should have");
|
|
ASSERT_IsTrue(_heapmaxavail() == 0, "heapmaxavail should be 0");
|
|
}
|
|
ENDTEST
|