xen/decompress: Drop bool_t and use bool instead
PATCH 1/1 xen/decompress: Drop bool_t and use bool instead
In particular, the libxg wrapper for unxz.c uses char for bool_t which is a major antipattern. Luckily the code doesn't suffer from truncated values.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
--- .../libs/guest/xg_dom_decompress_unsafe_xz.c | 1 - xen/common/unxz.c | 2 +- xen/common/xz/dec_bcj.c | 6 +++--- xen/common/xz/dec_lzma2.c | 20 +++++++++---------- xen/common/xz/dec_stream.c | 8 ++++---- xen/common/xz/lzma2.h | 2 +- xen/common/xz/private.h | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-)
tools/libs/guest/xg_dom_decompress_unsafe_xz.c +0 -1
@@ -11,7 +11,6 @@// TODO #define XZ_DEC_X86 -typedef char bool_t ;typedef uint8_t u8 ;typedef uint16_t u16 ;typedef uint32_t u32 ;
xen/common/unxz.c +1 -1
@@ -166,7 +166,7 @@ int __init unxz(unsigned char *in, unsigned int in_size,struct xz_buf b;struct xz_dec *s;enum xz_ret ret; -bool_t must_free_in = false; +bool must_free_in = false;xz_crc32_init ();
xen/common/xz/dec_bcj.c +3 -3
@@ -35,7 +35,7 @@ struct xz_dec_bcj {enum xz_ret ret;/* True if we are operating in single-call mode. */ -bool_t single_call; +bool single_call;/* * Absolute position relative to the beginning of the uncompressed
@@ -87,7 +87,7 @@ static inline int __init bcj_x86_test_msbyte(uint8_t b)static size_t __init bcj_x86 (struct xz_dec_bcj *s,uint8_t *buf,size_t size) { -static const bool_t mask_to_allowed_status[8 ] +static const bool mask_to_allowed_status[8 ] = { true, true, true, false, true, false, false, false };static const uint8_t mask_to_bit_num[8 ] = {0 ,1 ,2 ,2 ,3 ,3 ,3 ,3 };
@@ -524,7 +524,7 @@ XZ_EXTERN enum xz_ret __init xz_dec_bcj_run(struct xz_dec_bcj *s,return s->ret; } -XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool_t single_call) +XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool single_call) {struct xz_dec_bcj *s =malloc (sizeof (*s));if (s !=NULL )
xen/common/xz/dec_lzma2.c +10 -10
@@ -241,13 +241,13 @@ struct lzma2_dec {* True if dictionary reset is needed. This is false before * the first chunk (LZMA or uncompressed). */ -bool_t need_dict_reset; +bool need_dict_reset;/* * True if new LZMA properties are needed. This is false * before the first LZMA chunk. */ -bool_t need_props; +bool need_props; };struct xz_dec_lzma2 {
@@ -306,7 +306,7 @@ static void __init dict_limit(struct dictionary *dict, size_t out_max) }/* Return true if at least one byte can be written into the dictionary. */ -static inline bool_t __init dict_has_space (const struct dictionary *dict) +static inline bool __init dict_has_space (const struct dictionary *dict) {return dict->pos < dict->limit; }
@@ -343,7 +343,7 @@ static inline void __init dict_put(struct dictionary *dict, uint8_t byte)* invalid, false is returned. On success, true is returned and *len is * updated to indicate how many bytes were left to be repeated. */ -static bool_t __init dict_repeat (struct dictionary *dict,uint32_t *len,uint32_t dist) +static bool __init dict_repeat (struct dictionary *dict,uint32_t *len,uint32_t dist) {size_t back;uint32_t left;
@@ -463,7 +463,7 @@ static void __init rc_reset(struct rc_dec *rc)* Read the first five initial bytes into rc->code if they haven't been * read already. (Yes, the first byte gets completely ignored.) */ -static bool_t __init rc_read_init (struct rc_dec *rc,struct xz_buf *b) +static bool __init rc_read_init (struct rc_dec *rc,struct xz_buf *b) {while (rc->init_bytes_left >0 ) {if (b->in_pos == b->in_size)
@@ -477,7 +477,7 @@ static bool_t __init rc_read_init(struct rc_dec *rc, struct xz_buf *b) }/* Return true if there may not be enough input for the next decoding loop. */ -static inline bool_t __init rc_limit_exceeded (const struct rc_dec *rc) +static inline bool __init rc_limit_exceeded (const struct rc_dec *rc) {return rc->in_pos > rc->in_limit; }
@@ -486,7 +486,7 @@ static inline bool_t __init rc_limit_exceeded(const struct rc_dec *rc)* Return true if it is possible (from point of view of range decoder) that * we have reached the end of the LZMA chunk. */ -static inline bool_t __init rc_is_finished (const struct rc_dec *rc) +static inline bool __init rc_is_finished (const struct rc_dec *rc) {return rc->code ==0 ; }
@@ -736,7 +736,7 @@ static void __init lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state) }/* LZMA decoder core */ -static bool_t __init lzma_main (struct xz_dec_lzma2 *s) +static bool __init lzma_main (struct xz_dec_lzma2 *s) {uint32_t pos_state;
@@ -814,7 +814,7 @@ static void __init lzma_reset(struct xz_dec_lzma2 *s)* from the decoded lp and pb values. On success, the LZMA decoder state is * reset and true is returned. */ -static bool_t __init lzma_props (struct xz_dec_lzma2 *s,uint8_t props) +static bool __init lzma_props (struct xz_dec_lzma2 *s,uint8_t props) {if (props > (4 *5 +4 ) *9 +8 )return false;
@@ -861,7 +861,7 @@ static bool_t __init lzma_props(struct xz_dec_lzma2 *s, uint8_t props)* function. We decode a few bytes from the temporary buffer so that we can * continue decoding from the caller-supplied input buffer again. */ -static bool_t __init lzma2_lzma (struct xz_dec_lzma2 *s,struct xz_buf *b) +static bool __init lzma2_lzma (struct xz_dec_lzma2 *s,struct xz_buf *b) {size_t in_avail;uint32_t tmp;
xen/common/xz/dec_stream.c +4 -4
@@ -55,7 +55,7 @@ struct xz_dec {* True if the next call to xz_dec_run() is allowed to return * XZ_BUF_ERROR. */ -bool_t allow_buf_error; +bool allow_buf_error;/* Information stored in Block Header */ struct {
@@ -132,7 +132,7 @@ struct xz_dec {#ifdef XZ_DEC_BCJ struct xz_dec_bcj *bcj; -bool_t bcj_active; +bool bcj_active;#endif };
@@ -154,7 +154,7 @@ static const uint8_t check_sizes[16] = {* to copy into s->temp.buf. Return true once s->temp.pos has reached * s->temp.size. */ -static bool_t __init fill_temp (struct xz_dec *s,struct xz_buf *b) +static bool __init fill_temp (struct xz_dec *s,struct xz_buf *b) {size_t copy_size =min_t (size_t, b->in_size - b->in_pos, s->temp.size - s->temp.pos);
@@ -367,7 +367,7 @@ static enum xz_ret __init crc32_validate(struct xz_dec *s, struct xz_buf *b)* Skip over the Check field when the Check ID is not supported. * Returns true once the whole Check field has been skipped over. */ -static bool_t __init check_skip (struct xz_dec *s,struct xz_buf *b) +static bool __init check_skip (struct xz_dec *s,struct xz_buf *b) {while (s->pos < check_sizes[s->check_type]) {if (b->in_pos == b->in_size)
xen/common/xz/lzma2.h +1 -1
@@ -90,7 +90,7 @@ static inline void __init lzma_state_short_rep(enum lzma_state *state) }/* Test if the previous symbol was a literal. */ -static inline bool_t __init lzma_state_is_literal (enum lzma_state state) +static inline bool __init lzma_state_is_literal (enum lzma_state state) {return state <LIT_STATES ; }
xen/common/xz/private.h +1 -1
@@ -237,7 +237,7 @@ XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);* Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before * calling xz_dec_bcj_run(). */ -XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool_t single_call); +XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);/* * Decode the Filter ID of a BCJ filter. This implementation doesn't
Signature · 1 line
2.30.2
Quoted 6 lines · Andrew Cooper
In particular, the libxg wrapper for
unxz.cuses char forbool_twhich is a major antipattern. Luckily the code doesn't suffer from truncated values.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
FYI I checked patchew and it took the patch off of xen-devel, applied it to a branch, triggered a gitlab-ci pipeline, and it was successful:
https://gitlab.com/xen-project/patchew/xen/-/pipelines/906050463
All of this without me having to do anything! We live in the future.
Quoted 235 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>--- .../libs/guest/xg_dom_decompress_unsafe_xz.c | 1 - xen/common/unxz.c | 2 +- xen/common/xz/dec_bcj.c | 6 +++--- xen/common/xz/dec_lzma2.c | 20 +++++++++---------- xen/common/xz/dec_stream.c | 8 ++++---- xen/common/xz/lzma2.h | 2 +- xen/common/xz/private.h | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-)tools/libs/guest/xg_dom_decompress_unsafe_xz.c +0
-1@@ -11,7 +11,6 @@// TODO #define XZ_DEC_X86 -typedef char bool_t ;typedef uint8_t u8 ;typedef uint16_t u16 ;typedef uint32_t u32 ;xen/common/unxz.c +1
-1@@ -166,7 +166,7 @@ int __init unxz(unsigned char *in, unsigned int in_size,struct xz_buf b;struct xz_dec *s;enum xz_ret ret; -bool_t must_free_in = false; +bool must_free_in = false;xz_crc32_init ();xen/common/xz/dec_bcj.c +3
-3@@ -35,7 +35,7 @@ struct xz_dec_bcj {enum xz_ret ret;/* True if we are operating in single-call mode. */ -bool_t single_call; +bool single_call;/* * Absolute position relative to the beginning of the uncompressed @@ -87,7 +87,7 @@ static inline int __init bcj_x86_test_msbyte(uint8_t b)static size_t __init bcj_x86 (struct xz_dec_bcj *s,uint8_t *buf,size_t size) { -static const bool_t mask_to_allowed_status[8 ] +static const bool mask_to_allowed_status[8 ] = { true, true, true, false, true, false, false, false };static const uint8_t mask_to_bit_num[8 ] = {0 ,1 ,2 ,2 ,3 ,3 ,3 ,3 };@@ -524,7 +524,7 @@ XZ_EXTERN enum xz_ret __init xz_dec_bcj_run(struct xz_dec_bcj *s,return s->ret; } -XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool_t single_call) +XZ_EXTERN struct xz_dec_bcj *__init xz_dec_bcj_create(bool single_call) {struct xz_dec_bcj *s =malloc (sizeof (*s));if (s !=NULL )xen/common/xz/dec_lzma2.c +10
-10@@ -241,13 +241,13 @@ struct lzma2_dec {* True if dictionary reset is needed. This is false before * the first chunk (LZMA or uncompressed). */ -bool_t need_dict_reset; +bool need_dict_reset;/* * True if new LZMA properties are needed. This is false * before the first LZMA chunk. */ -bool_t need_props; +bool need_props; };struct xz_dec_lzma2 {@@ -306,7 +306,7 @@ static void __init dict_limit(struct dictionary *dict, size_t out_max) }/* Return true if at least one byte can be written into the dictionary. */ -static inline bool_t __init dict_has_space (const struct dictionary *dict) +static inline bool __init dict_has_space (const struct dictionary *dict) {return dict->pos < dict->limit; }@@ -343,7 +343,7 @@ static inline void __init dict_put(struct dictionary *dict, uint8_t byte)* invalid, false is returned. On success, true is returned and *len is * updated to indicate how many bytes were left to be repeated. */ -static bool_t __init dict_repeat (struct dictionary *dict,uint32_t *len,uint32_t dist) +static bool __init dict_repeat (struct dictionary *dict,uint32_t *len,uint32_t dist) {size_t back;uint32_t left;@@ -463,7 +463,7 @@ static void __init rc_reset(struct rc_dec *rc)* Read the first five initial bytes into rc->code if they haven't been * read already. (Yes, the first byte gets completely ignored.) */ -static bool_t __init rc_read_init (struct rc_dec *rc,struct xz_buf *b) +static bool __init rc_read_init (struct rc_dec *rc,struct xz_buf *b) {while (rc->init_bytes_left >0 ) {if (b->in_pos == b->in_size)@@ -477,7 +477,7 @@ static bool_t __init rc_read_init(struct rc_dec *rc, struct xz_buf *b) }/* Return true if there may not be enough input for the next decoding loop. */ -static inline bool_t __init rc_limit_exceeded (const struct rc_dec *rc) +static inline bool __init rc_limit_exceeded (const struct rc_dec *rc) {return rc->in_pos > rc->in_limit; }@@ -486,7 +486,7 @@ static inline bool_t __init rc_limit_exceeded(const struct rc_dec *rc)* Return true if it is possible (from point of view of range decoder) that * we have reached the end of the LZMA chunk. */ -static inline bool_t __init rc_is_finished (const struct rc_dec *rc) +static inline bool __init rc_is_finished (const struct rc_dec *rc) {return rc->code ==0 ; }@@ -736,7 +736,7 @@ static void __init lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state) }/* LZMA decoder core */ -static bool_t __init lzma_main (struct xz_dec_lzma2 *s) +static bool __init lzma_main (struct xz_dec_lzma2 *s) {uint32_t pos_state;@@ -814,7 +814,7 @@ static void __init lzma_reset(struct xz_dec_lzma2 *s)* from the decoded lp and pb values. On success, the LZMA decoder state is * reset and true is returned. */ -static bool_t __init lzma_props (struct xz_dec_lzma2 *s,uint8_t props) +static bool __init lzma_props (struct xz_dec_lzma2 *s,uint8_t props) {if (props > (4 *5 +4 ) *9 +8 )return false;@@ -861,7 +861,7 @@ static bool_t __init lzma_props(struct xz_dec_lzma2 *s, uint8_t props)* function. We decode a few bytes from the temporary buffer so that we can * continue decoding from the caller-supplied input buffer again. */ -static bool_t __init lzma2_lzma (struct xz_dec_lzma2 *s,struct xz_buf *b) +static bool __init lzma2_lzma (struct xz_dec_lzma2 *s,struct xz_buf *b) {size_t in_avail;uint32_t tmp;xen/common/xz/dec_stream.c +4
-4@@ -55,7 +55,7 @@ struct xz_dec {* True if the next call to xz_dec_run() is allowed to return * XZ_BUF_ERROR. */ -bool_t allow_buf_error; +bool allow_buf_error;/* Information stored in Block Header */ struct {@@ -132,7 +132,7 @@ struct xz_dec {#ifdef XZ_DEC_BCJ struct xz_dec_bcj *bcj; -bool_t bcj_active; +bool bcj_active;#endif };@@ -154,7 +154,7 @@ static const uint8_t check_sizes[16] = {* to copy into s->temp.buf. Return true once s->temp.pos has reached * s->temp.size. */ -static bool_t __init fill_temp (struct xz_dec *s,struct xz_buf *b) +static bool __init fill_temp (struct xz_dec *s,struct xz_buf *b) {size_t copy_size =min_t (size_t, b->in_size - b->in_pos, s->temp.size - s->temp.pos);@@ -367,7 +367,7 @@ static enum xz_ret __init crc32_validate(struct xz_dec *s, struct xz_buf *b)* Skip over the Check field when the Check ID is not supported. * Returns true once the whole Check field has been skipped over. */ -static bool_t __init check_skip (struct xz_dec *s,struct xz_buf *b) +static bool __init check_skip (struct xz_dec *s,struct xz_buf *b) {while (s->pos < check_sizes[s->check_type]) {if (b->in_pos == b->in_size)xen/common/xz/lzma2.h +1
-1@@ -90,7 +90,7 @@ static inline void __init lzma_state_short_rep(enum lzma_state *state) }/* Test if the previous symbol was a literal. */ -static inline bool_t __init lzma_state_is_literal (enum lzma_state state) +static inline bool __init lzma_state_is_literal (enum lzma_state state) {return state <LIT_STATES ; }xen/common/xz/private.h +1
-1@@ -237,7 +237,7 @@ XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);* Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before * calling xz_dec_bcj_run(). */ -XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool_t single_call); +XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);/* * Decode the Filter ID of a BCJ filter. This implementation doesn't Signature · 1 line
2.30.2