mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #4270
4270: Try to catch #4240 in action r=def- a=Learath2 <!-- What is the motivation for the changes of this pull request --> This allocates characters dynamically so hopefully asan will point out the use-after-free. ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [x] Considered possible null pointers and out of bounds array indexing - [x] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
76b519b856
|
@ -30,6 +30,27 @@ public: \
|
||||||
\
|
\
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
#if defined(__has_feature)
|
||||||
|
#if __has_feature(address_sanitizer)
|
||||||
|
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
||||||
|
void *POOLTYPE::operator new(size_t Size, int id) \
|
||||||
|
{ \
|
||||||
|
void *p = malloc(Size); \
|
||||||
|
mem_zero(p, Size); \
|
||||||
|
return p; \
|
||||||
|
} \
|
||||||
|
void POOLTYPE::operator delete(void *p, int id) \
|
||||||
|
{ \
|
||||||
|
free(p); \
|
||||||
|
} \
|
||||||
|
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
|
||||||
|
{ \
|
||||||
|
free(p); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MACRO_ALLOC_POOL_ID_IMPL
|
||||||
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
|
||||||
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
|
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
|
||||||
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
|
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
|
||||||
|
@ -58,5 +79,6 @@ private:
|
||||||
ms_PoolUsed##POOLTYPE[id] = 0; \
|
ms_PoolUsed##POOLTYPE[id] = 0; \
|
||||||
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue