VALID() wasn't properly handling NULL returns, leading to false positives

This commit is contained in:
2026-05-24 19:14:35 -04:00
parent 7700af06a1
commit 235033d633
2 changed files with 6 additions and 2 deletions

View File

@@ -185,7 +185,7 @@ void akerr_init_errno(void);
#define VALID(__err_context, __stmt) \ #define VALID(__err_context, __stmt) \
__stmt; \ __stmt; \
if ( akerr_valid_error_address(__err_context) == 1 ) { \ if ( akerr_valid_error_address(__err_context) == 0 ) { \
FAIL(__err_context, AKERR_BEHAVIOR, "Received (akerr_Error *) from an invalid memory region. (Did the method finish without calling SUCCEED_RETURN?)"); \ FAIL(__err_context, AKERR_BEHAVIOR, "Received (akerr_Error *) from an invalid memory region. (Did the method finish without calling SUCCEED_RETURN?)"); \
} }

View File

@@ -17,7 +17,11 @@ akerr_ErrorContext AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR];
int akerr_valid_error_address(akerr_ErrorContext *ptr) int akerr_valid_error_address(akerr_ErrorContext *ptr)
{ {
// Is this within the memory region occupied by AKERR_ARRAY_ERROR? // Is this within the memory region occupied by AKERR_ARRAY_ERROR?
return ((ptr >= &AKERR_ARRAY_ERROR[0]) && (ptr <= &AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR-1])); if ( ptr == NULL ) {
return 1;
}
return ((ptr >= &AKERR_ARRAY_ERROR[0]) &&
(ptr <= &AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR-1]));
} }
void akerr_default_logger(const char *fmt, ...) void akerr_default_logger(const char *fmt, ...)