From: Yann Collet Date: Tue, 22 Oct 2024 23:22:17 +0000 (-0700) Subject: rewrote ZSTD_cwksp_initialAllocStart() to be easier to read X-Git-Tag: v1.5.7^2~71^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06b7cfabf8f5f3ba48694758cf85aaf7671504d2;p=thirdparty%2Fzstd.git rewrote ZSTD_cwksp_initialAllocStart() to be easier to read following a discussion with @felixhandte --- diff --git a/lib/compress/zstd_cwksp.h b/lib/compress/zstd_cwksp.h index 77715e22e..aa4c3e49e 100644 --- a/lib/compress/zstd_cwksp.h +++ b/lib/compress/zstd_cwksp.h @@ -17,6 +17,7 @@ #include "../common/allocations.h" /* ZSTD_customMalloc, ZSTD_customFree */ #include "../common/zstd_internal.h" #include "../common/portability_macros.h" +#include "../common/compiler.h" /* ZS2_isPower2 */ #if defined (__cplusplus) extern "C" { @@ -275,8 +276,12 @@ MEM_STATIC size_t ZSTD_cwksp_bytes_to_align_ptr(void* ptr, const size_t alignByt * Returns the initial value for allocStart which is used to determine the position from * which we can allocate from the end of the workspace. */ -MEM_STATIC void* ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws) { - return (void*)((size_t)ws->workspaceEnd & (size_t)~(ZSTD_CWKSP_ALIGNMENT_BYTES-1)); +MEM_STATIC void* ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws) +{ + char* endPtr = (char*)ws->workspaceEnd; + assert(ZSTD_isPower2(ZSTD_CWKSP_ALIGNMENT_BYTES)); + endPtr = endPtr - ((size_t)endPtr % ZSTD_CWKSP_ALIGNMENT_BYTES); + return (void*)endPtr; } /**