mem/tests/02_new.c

30 lines
594 B
C
Raw Normal View History

2025-07-04 00:04:47 +00:00
#define DEBUG
#include "../include/except.h"
#include "../include/mem.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define BUFSZ 100
static bool isZeroed(void *memory, unsigned int size)
{
unsigned char *mm = (unsigned char*)memory;
// early out for empty size
if (size == 0) return true;
return (*mm == 0) && memcmp(mm, mm + 1, size - 1) == 0;
}
int main(void){
char *buf = NEW(buf);
ASSERTED(buf != NULL);
ASSERTED(isZeroed(buf, BUFSZ) == false);
FREE(buf);
ASSERTED(buf == NULL);
return EXIT_SUCCESS;
}