1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Use uintptr_t in ASSERT_ALLOC_VALID() to avoid pointer arithmetic.

Clang justifiably complains about pointer arithmetic on a known NULL value during testing. We know this is fine but use uintptr_t to silence the warnings.

Found on MacOS M1.
This commit is contained in:
David Steele
2021-01-22 10:48:22 -05:00
parent 185a508f44
commit b23a2a0baf
2 changed files with 2 additions and 2 deletions

View File

@ -41,7 +41,7 @@ typedef struct MemContextAlloc
// belongs to another context. Otherwise, there is likely to be a segfault. // belongs to another context. Otherwise, there is likely to be a segfault.
#define ASSERT_ALLOC_VALID(alloc) \ #define ASSERT_ALLOC_VALID(alloc) \
ASSERT( \ ASSERT( \
alloc != NULL && alloc != MEM_CONTEXT_ALLOC_HEADER(NULL) && \ alloc != NULL && (uintptr_t)alloc != (uintptr_t)-sizeof(MemContextAlloc) && \
alloc->allocIdx < memContextStack[memContextCurrentStackIdx].memContext->allocListSize && \ alloc->allocIdx < memContextStack[memContextCurrentStackIdx].memContext->allocListSize && \
memContextStack[memContextCurrentStackIdx].memContext->allocList[alloc->allocIdx]); memContextStack[memContextCurrentStackIdx].memContext->allocList[alloc->allocIdx]);

View File

@ -228,7 +228,7 @@ testRun(void)
TEST_ERROR( TEST_ERROR(
memFree(NULL), AssertError, memFree(NULL), AssertError,
"assertion '((MemContextAlloc *)buffer - 1) != NULL" "assertion '((MemContextAlloc *)buffer - 1) != NULL"
" && ((MemContextAlloc *)buffer - 1) != MEM_CONTEXT_ALLOC_HEADER(NULL)" " && (uintptr_t)((MemContextAlloc *)buffer - 1) != (uintptr_t)-sizeof(MemContextAlloc)"
" && ((MemContextAlloc *)buffer - 1)->allocIdx <" " && ((MemContextAlloc *)buffer - 1)->allocIdx <"
" memContextStack[memContextCurrentStackIdx].memContext->allocListSize" " memContextStack[memContextCurrentStackIdx].memContext->allocListSize"
" && memContextStack[memContextCurrentStackIdx].memContext->allocList[((MemContextAlloc *)buffer - 1)->allocIdx]'" " && memContextStack[memContextCurrentStackIdx].memContext->allocList[((MemContextAlloc *)buffer - 1)->allocIdx]'"