diff options
| author | Shauren <shauren.trinity@gmail.com> | 2022-11-03 01:15:30 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2022-11-03 01:15:30 +0100 |
| commit | c4564566b0b308f88f3664ec124a8557bdc278f0 (patch) | |
| tree | f09d604f961e5d605556bc652aea5ec5d505d025 /dep/CascLib/src/common/Common.h | |
| parent | 722201e01c7809f1e85eb480499630a7d7d748b5 (diff) | |
Dep/CascLib: Update to ladislav-zezula/CascLib@136c6e05537bd7123620ddb28671d1f2cf060e0b
Diffstat (limited to 'dep/CascLib/src/common/Common.h')
| -rw-r--r-- | dep/CascLib/src/common/Common.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/dep/CascLib/src/common/Common.h b/dep/CascLib/src/common/Common.h index 63996e5503c..3fbbf0d842c 100644 --- a/dep/CascLib/src/common/Common.h +++ b/dep/CascLib/src/common/Common.h @@ -140,7 +140,16 @@ extern unsigned char IntToHexChar[]; // - Memory freeing function must check for NULL pointer and do nothing if so // -#define CASC_REALLOC(type, ptr, count) (type *)realloc(ptr, (count) * sizeof(type)) +template <typename T> +T * CASC_REALLOC(T * old_ptr, size_t count) +{ + T * new_ptr = (T *)realloc(old_ptr, count * sizeof(T)); + + // If realloc fails, then the old buffer remains unfreed + if(new_ptr == NULL) + free(old_ptr); + return new_ptr; +} template <typename T> T * CASC_ALLOC(size_t nCount) |
