Files
Rot127andCopilot Autofix powered by AI 475d554285 Replace all system allocations with cs_mem_ allocations. (#3074)
* Add several NULL checks for the dynamic memory functions.

This adds the requirement to the API, that all cs_opt_mem members
must be defined.

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
2026-09-15 13:02:50 +00:00

56 lines
1.3 KiB
C

// Copyright © 2026 Rot127 <[email protected]>
// SPDX-License-Identifier: BSD-3
#include "../../include/capstone/capstone.h"
#include "unit_test.h"
#include <stdio.h>
#include <string.h>
static bool test_cs_mem_setup_fail()
{
printf("Test test_cs_mem_setup_fail\n");
cs_opt_mem mem = { .malloc = malloc,
.calloc = calloc,
.realloc = realloc,
.free = free,
.vsnprintf = NULL };
CHECK_INT_EQUAL_RET_FALSE((size_t)cs_option(0, CS_OPT_MEM,
(size_t)&mem),
CS_ERR_MEMSETUP);
mem.vsnprintf = vsnprintf;
mem.malloc = NULL;
CHECK_INT_EQUAL_RET_FALSE((size_t)cs_option(0, CS_OPT_MEM,
(size_t)&mem),
CS_ERR_MEMSETUP);
mem.malloc = malloc;
mem.calloc = NULL;
CHECK_INT_EQUAL_RET_FALSE((size_t)cs_option(0, CS_OPT_MEM,
(size_t)&mem),
CS_ERR_MEMSETUP);
mem.calloc = calloc;
mem.realloc = NULL;
CHECK_INT_EQUAL_RET_FALSE((size_t)cs_option(0, CS_OPT_MEM,
(size_t)&mem),
CS_ERR_MEMSETUP);
mem.realloc = realloc;
mem.free = NULL;
CHECK_INT_EQUAL_RET_FALSE((size_t)cs_option(0, CS_OPT_MEM,
(size_t)&mem),
CS_ERR_MEMSETUP);
return true;
}
int main()
{
bool result = true;
result &= test_cs_mem_setup_fail();
if (result) {
printf("All tests passed.\n");
} else {
printf("Some tests failed.\n");
}
return result ? 0 : -1;
}