]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
regroup all mentions of ZSTD_REP_MOVE within zstd_compress_internal.h
authorYann Collet <cyan@fb.com>
Tue, 28 Dec 2021 21:47:57 +0000 (13:47 -0800)
committerYann Collet <cyan@fb.com>
Tue, 28 Dec 2021 21:47:57 +0000 (13:47 -0800)
lib/common/zstd_internal.h
lib/compress/zstd_compress_internal.h
lib/compress/zstd_lazy.c

index 32ef0b43eb422b131b8507fe4357b3d5af624e4d..e4d36ce09051b93cb6bdc30c6233b9bfab314dbc 100644 (file)
@@ -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)
index 9ad0db6dada70c594cd9df01221d065969e87290..2d55ddd716ae56394243dfa6bcbe924091dc6607 100644 (file)
@@ -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.
 */
index cb3152eb86a2fea33c63f4969634427b0e191239..72bbe719537849f61b34a83a61f6fd03cd679127 100644 (file)
@@ -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) {