[PATCH 2/2] DRAFT *** lib/xz: Convert even more uses of uint32_t to size_t
From: Lasse Collin
Date: Fri Jun 12 2026 - 15:09:41 EST
---
lib/xz/xz_dec_lzma2.c | 62 +++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/lib/xz/xz_dec_lzma2.c b/lib/xz/xz_dec_lzma2.c
index 087385e5d9a7..685c0efa4328 100644
--- a/lib/xz/xz_dec_lzma2.c
+++ b/lib/xz/xz_dec_lzma2.c
@@ -130,10 +130,10 @@ struct lzma_len_dec {
struct lzma_dec {
/* Distances of latest four matches */
- uint32_t rep0;
- uint32_t rep1;
- uint32_t rep2;
- uint32_t rep3;
+ size_t rep0;
+ size_t rep1;
+ size_t rep2;
+ size_t rep3;
/*
* Length of a match. This is updated so that dict_repeat can
@@ -150,9 +150,9 @@ struct lzma_dec {
* position bits, and a mask derived from the number
* position bits)
*/
- uint32_t lc;
- uint32_t literal_pos_mask; /* (1 << lp) - 1 */
- uint32_t pos_mask; /* (1 << pb) - 1 */
+ size_t lc;
+ size_t literal_pos_mask; /* (1 << lp) - 1 */
+ size_t pos_mask; /* (1 << pb) - 1 */
/* If 1, it's a match. Otherwise it's a single 8-bit literal. */
uint16_t is_match[STATES][POS_STATES_MAX];
@@ -320,7 +320,7 @@ static inline bool dict_has_space(const struct dictionary *dict)
* still empty. This special case is needed for single-call decoding to
* avoid writing a '\0' to the end of the destination buffer.
*/
-static inline uint32_t dict_get(const struct dictionary *dict, size_t dist)
+static inline size_t dict_get(const struct dictionary *dict, size_t dist)
{
size_t offset = dict->pos - dist - 1;
@@ -547,10 +547,10 @@ static __always_inline int rc_bit(struct rc_dec *rc, uint16_t *prob)
}
/* Decode a bittree starting from the most significant bit. */
-static __always_inline uint32_t rc_bittree(struct rc_dec *rc,
- uint16_t *probs, uint32_t limit)
+static __always_inline size_t rc_bittree(struct rc_dec *rc,
+ uint16_t *probs, size_t limit)
{
- uint32_t symbol = 1;
+ size_t symbol = 1;
do {
if (rc_bit(rc, &probs[symbol]))
@@ -565,10 +565,10 @@ static __always_inline uint32_t rc_bittree(struct rc_dec *rc,
/* Decode a bittree starting from the least significant bit. */
static __always_inline void rc_bittree_reverse(struct rc_dec *rc,
uint16_t *probs,
- uint32_t *dest, uint32_t limit)
+ size_t *dest, size_t limit)
{
- uint32_t symbol = 1;
- uint32_t i = 0;
+ size_t symbol = 1;
+ size_t i = 0;
do {
if (rc_bit(rc, &probs[symbol])) {
@@ -581,7 +581,7 @@ static __always_inline void rc_bittree_reverse(struct rc_dec *rc,
}
/* Decode direct bits (fixed fifty-fifty probability) */
-static inline void rc_direct(struct rc_dec *rc, uint32_t *dest, uint32_t limit)
+static inline void rc_direct(struct rc_dec *rc, size_t *dest, size_t limit)
{
uint32_t mask;
@@ -602,9 +602,9 @@ static inline void rc_direct(struct rc_dec *rc, uint32_t *dest, uint32_t limit)
/* Get pointer to literal coder probability array. */
static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s)
{
- uint32_t prev_byte = dict_get(&s->dict, 0);
- uint32_t low = prev_byte >> (8 - s->lzma.lc);
- uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
+ size_t prev_byte = dict_get(&s->dict, 0);
+ size_t low = prev_byte >> (8 - s->lzma.lc);
+ size_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
return s->lzma.literal[low + high];
}
@@ -612,11 +612,11 @@ static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s)
static void lzma_literal(struct xz_dec_lzma2 *s)
{
uint16_t *probs;
- uint32_t symbol;
- uint32_t match_byte;
- uint32_t match_bit;
- uint32_t offset;
- uint32_t i;
+ size_t symbol;
+ size_t match_byte;
+ size_t match_bit;
+ size_t offset;
+ size_t i;
probs = lzma_literal_probs(s);
@@ -648,10 +648,10 @@ static void lzma_literal(struct xz_dec_lzma2 *s)
/* Decode the length of the match into s->lzma.len. */
static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
- uint32_t pos_state)
+ size_t pos_state)
{
uint16_t *probs;
- uint32_t limit;
+ size_t limit;
if (!rc_bit(&s->rc, &l->choice)) {
probs = l->low[pos_state];
@@ -674,11 +674,11 @@ static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
}
/* Decode a match. The distance will be stored in s->lzma.rep0. */
-static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
+static void lzma_match(struct xz_dec_lzma2 *s, size_t pos_state)
{
uint16_t *probs;
- uint32_t dist_slot;
- uint32_t limit;
+ size_t dist_slot;
+ size_t limit;
lzma_state_match(&s->lzma.state);
@@ -716,9 +716,9 @@ static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
* Decode a repeated match. The distance is one of the four most recently
* seen matches. The distance will be stored in s->lzma.rep0.
*/
-static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
+static void lzma_rep_match(struct xz_dec_lzma2 *s, size_t pos_state)
{
- uint32_t tmp;
+ size_t tmp;
if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) {
if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[
@@ -752,7 +752,7 @@ static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
/* LZMA decoder core */
static bool lzma_main(struct xz_dec_lzma2 *s)
{
- uint32_t pos_state;
+ size_t pos_state;
/*
* If the dictionary was reached during the previous call, try to
--
2.54.0
--MP_/Nfnb21b6ufhU/gDEj3AWmMB--