cJSON
[Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065)
Brought by drakestapleton
cJSON / tests / unity / extras / fixture / src / unity_fixture_malloc_overrides.h
| 1 | /* Copyright (c) 2010 James Grenning and Contributed to Unity Project |
| 2 | * ========================================== |
| 3 | * Unity Project - A Test Framework for C |
| 4 | * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams |
| 5 | * [Released under MIT License. Please refer to license.txt for details] |
| 6 | * ========================================== */ |
| 7 | |
| 8 | #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ |
| 9 | #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ |
| 10 | |
| 11 | #include <stddef.h> |
| 12 | |
| 13 | #ifdef UNITY_EXCLUDE_STDLIB_MALLOC |
| 14 | /* Define this macro to remove the use of stdlib.h, malloc, and free. |
| 15 | * Many embedded systems do not have a heap or malloc/free by default. |
| 16 | * This internal unity_malloc() provides allocated memory deterministically from |
| 17 | * the end of an array only, unity_free() only releases from end-of-array, |
| 18 | * blocks are not coalesced, and memory not freed in LIFO order is stranded. */ |
| 19 | #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES |
| 20 | #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256 |
| 21 | #endif |
| 22 | #endif |
| 23 | |
| 24 | /* These functions are used by the Unity Fixture to allocate and release memory |
| 25 | * on the heap and can be overridden with platform-specific implementations. |
| 26 | * For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc() |
| 27 | * and UNITY_FIXTURE_FREE becomes vPortFree(). */ |
| 28 | #if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE) |
| 29 | #include <stdlib.h> |
| 30 | #define UNITY_FIXTURE_MALLOC(size) malloc(size) |
| 31 | #define UNITY_FIXTURE_FREE(ptr) free(ptr) |
| 32 | #else |
| 33 | extern void* UNITY_FIXTURE_MALLOC(size_t size); |
| 34 | extern void UNITY_FIXTURE_FREE(void* ptr); |
| 35 | #endif |
| 36 | |
| 37 | #define malloc unity_malloc |
| 38 | #define calloc unity_calloc |
| 39 | #define realloc unity_realloc |
| 40 | #define free unity_free |
| 41 | |
| 42 | void* unity_malloc(size_t size); |
| 43 | void* unity_calloc(size_t num, size_t size); |
| 44 | void* unity_realloc(void * oldMem, size_t size); |
| 45 | void unity_free(void * mem); |
| 46 | |
| 47 | #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ |