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:
bors[bot] 2021-11-01 15:16:08 +00:00 committed by GitHub
commit 76b519b856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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