From: Yann Collet Date: Tue, 28 Dec 2021 21:47:57 +0000 (-0800) Subject: regroup all mentions of ZSTD_REP_MOVE within zstd_compress_internal.h X-Git-Tag: v1.5.2^2~21^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de9f52e9456f97a3bdf6c2b4ecad424226d65247;p=thirdparty%2Fzstd.git regroup all mentions of ZSTD_REP_MOVE within zstd_compress_internal.h --- diff --git a/lib/common/zstd_internal.h b/lib/common/zstd_internal.h index 32ef0b43e..e4d36ce09 100644 --- a/lib/common/zstd_internal.h +++ b/lib/common/zstd_internal.h @@ -67,7 +67,6 @@ extern "C" { #define ZSTD_OPT_NUM (1<<12) #define ZSTD_REP_NUM 3 /* number of repcodes */ -#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1) static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 }; #define KB *(1 <<10) diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index 9ad0db6da..2d55ddd71 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -129,7 +129,7 @@ size_t ZSTD_buildBlockEntropyStats(seqStore_t* seqStorePtr, *********************************/ typedef struct { - U32 off; /* Offset code (offset + ZSTD_REP_MOVE) for the match */ + U32 off; /* Offset sumtype code for the match, using ZSTD_storeSeq() format */ U32 len; /* Raw length of match */ } ZSTD_match_t; @@ -577,22 +577,21 @@ ZSTD_safecopyLiterals(BYTE* op, BYTE const* ip, BYTE const* const iend, BYTE con while (ip < iend) *op++ = *ip++; } +#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1) #define STORE_REPCODE_1 STORE_REPCODE(1) #define STORE_REPCODE_2 STORE_REPCODE(2) #define STORE_REPCODE_3 STORE_REPCODE(3) #define STORE_REPCODE(r) (assert((r)>=1), assert((r)<=3), (r)-1) #define STORE_OFFSET(o) (assert((o)>0), o + ZSTD_REP_MOVE) #define STORED_IS_OFFSET(o) ((o) > ZSTD_REP_MOVE) -#define STORED_IS_REPCODE(o) ((o) < ZSTD_REP_NUM) +#define STORED_IS_REPCODE(o) ((o) <= ZSTD_REP_MOVE) #define STORED_OFFSET(o) (assert(STORED_IS_OFFSET(o)), (o)-ZSTD_REP_MOVE) #define STORED_REPCODE(o) (assert(STORED_IS_REPCODE(o)), (o)+1) /* returns ID 1,2,3 */ #define STORED_TO_OFFBASE(o) ((o)+1) /*! ZSTD_storeSeq() : * Store a sequence (litlen, litPtr, offCode and matchLength) into seqStore_t. - * @offBase_minus1 : distance to match + ZSTD_REP_MOVE (values <= ZSTD_REP_MOVE are repCodes). - * Users should not specify the encoded value directly, - * instead use macros STORE_REPCODE_X and STORE_OFFSET(). + * @offBase_minus1 : Users should use employ macros STORE_REPCODE_X and STORE_OFFSET(). * @matchLength : must be >= MINMATCH * Allowed to overread literals up to litLimit. */ diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index cb3152eb8..72bbe7195 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -1648,9 +1648,8 @@ ZSTD_compressBlock_lazy_generic( } /* NOTE: - * start[-offset+ZSTD_REP_MOVE-1] is undefined behavior. - * (-offset+ZSTD_REP_MOVE-1) is unsigned, and is added to start, which - * overflows the pointer, which is undefined behavior. + * Pay attention that `start[-value]` can lead to strange undefined behavior + * notably if `value` is unsigned, resulting in a large positive `-value`. */ /* catch up */ if (offcode) {