diff --git a/lib/common/cmp_debug.h b/lib/common/cmp_debug.h index 6c737d7e2057bacaafd4d9093bb3c19fd0c48b9b..f95dc2e96964cef2ba81c41f8d1675740606c42a 100644 --- a/lib/common/cmp_debug.h +++ b/lib/common/cmp_debug.h @@ -19,6 +19,13 @@ #ifndef CMP_DEBUG_H #define CMP_DEBUG_H + +/* DEBUGLEVEL should be externally defined, usually via the compiler command + * line. Its value must be a numeric value. */ +#ifndef DEBUGLEVEL +# define DEBUGLEVEL 0 +#endif + #if !defined(ICU_ASW) && (defined(DEBUG) || DEBUGLEVEL > 0) #include <stdio.h> __extension__ diff --git a/lib/common/cmp_entity.c b/lib/common/cmp_entity.c index 3e4bf65664d642bfb9fd056cf052b16520b533ab..82c697c18345ecbec14c1ce088cf54343082b073 100644 --- a/lib/common/cmp_entity.c +++ b/lib/common/cmp_entity.c @@ -2210,7 +2210,7 @@ uint64_t cmp_ent_create_timestamp(const struct timespec *ts) void cmp_ent_print_header(const struct cmp_entity *ent) { - const uint8_t *p = (const uint8_t *)ent; + MAYBE_UNUSED const uint8_t *p = (const uint8_t *)ent; uint32_t hdr_size = cmp_ent_get_hdr_size(ent); size_t i; @@ -2262,17 +2262,17 @@ void cmp_ent_print(struct cmp_entity *ent) static void cmp_ent_parse_generic_header(const struct cmp_entity *ent) { - uint32_t version_id, cmp_ent_size, original_size, cmp_mode_used, + MAYBE_UNUSED uint32_t version_id, cmp_ent_size, original_size, cmp_mode_used, model_value_used, model_id, model_counter, max_used_bits_version, lossy_cmp_par_used, start_coarse_time, end_coarse_time; - uint16_t start_fine_time, end_fine_time; - enum cmp_data_type data_type; - int raw_bit; + MAYBE_UNUSED uint16_t start_fine_time, end_fine_time; + MAYBE_UNUSED enum cmp_data_type data_type; + MAYBE_UNUSED int raw_bit; version_id = cmp_ent_get_version_id(ent); if (version_id & CMP_TOOL_VERSION_ID_BIT) { - uint16_t major = (version_id & 0x7FFF0000U) >> 16U; - uint16_t minor = version_id & 0xFFFFU; + MAYBE_UNUSED uint16_t major = (version_id & 0x7FFF0000U) >> 16U; + MAYBE_UNUSED uint16_t minor = version_id & 0xFFFFU; debug_print("Compressed with cmp_tool version: %u.%02u", major, minor); } else @@ -2299,7 +2299,7 @@ static void cmp_ent_parse_generic_header(const struct cmp_entity *ent) #ifdef HAS_TIME_H { struct tm epoch_date = PLATO_EPOCH_DATE; - time_t time = my_timegm(&epoch_date) + start_coarse_time; + MAYBE_UNUSED time_t time = my_timegm(&epoch_date) + start_coarse_time; debug_print("Data were compressed on (local time): %s", ctime(&time)); } @@ -2341,7 +2341,7 @@ static void cmp_ent_parse_generic_header(const struct cmp_entity *ent) static void cmp_ent_parese_imagette_header(const struct cmp_entity *ent) { - uint32_t spill_used, golomb_par_used; + MAYBE_UNUSED uint32_t spill_used, golomb_par_used; spill_used = cmp_ent_get_ima_spill(ent); debug_print("Used Spillover Threshold Parameter: %" PRIu32, spill_used); @@ -2359,7 +2359,7 @@ static void cmp_ent_parese_imagette_header(const struct cmp_entity *ent) static void cmp_ent_parese_adaptive_imagette_header(const struct cmp_entity *ent) { - uint32_t spill_used, golomb_par_used, ap1_spill_used, + MAYBE_UNUSED uint32_t spill_used, golomb_par_used, ap1_spill_used, ap1_golomb_par_used, ap2_spill_used, ap2_golomb_par_used; spill_used = cmp_ent_get_ima_spill(ent); @@ -2390,7 +2390,7 @@ static void cmp_ent_parese_adaptive_imagette_header(const struct cmp_entity *ent static void cmp_ent_parese_non_imagette_header(const struct cmp_entity *ent) { - uint32_t spill_1_used, cmp_par_1_used, spill_2_used, cmp_par_2_used, + MAYBE_UNUSED uint32_t spill_1_used, cmp_par_1_used, spill_2_used, cmp_par_2_used, spill_3_used, cmp_par_3_used, spill_4_used, cmp_par_4_used, spill_5_used, cmp_par_5_used; diff --git a/lib/common/cmp_support.c b/lib/common/cmp_support.c index 02ccd813a31e6565b0f4106b3a82639ac85d21da..fe6d486b94102937d74691ae7e915bb52346eb3e 100644 --- a/lib/common/cmp_support.c +++ b/lib/common/cmp_support.c @@ -411,7 +411,7 @@ int cmp_cfg_gen_par_is_invalid(const struct cmp_cfg *cfg, enum check_opt opt) int unsupported_cmp_mode; int check_model_value; uint32_t max_round_value = 0; - const char *str = ""; + MAYBE_UNUSED const char *str = ""; if (!cfg) return 1; @@ -619,7 +619,7 @@ int cmp_cfg_icu_max_used_bits_out_of_limit(const struct cmp_max_used_bits *max_u */ static int cmp_pars_are_invalid(uint32_t cmp_par, uint32_t spill, enum cmp_mode cmp_mode, - enum cmp_data_type data_type, const char *par_name) + enum cmp_data_type data_type, const char *par_name MAYBE_UNUSED) { int cfg_invalid = 0; uint32_t min_golomb_par; diff --git a/lib/common/compiler.h b/lib/common/compiler.h index 206ecc7c0ee603d99a2b5702123dadb1da6c102e..510057c77989eac301dc18095ff1a8d6208dee80 100644 --- a/lib/common/compiler.h +++ b/lib/common/compiler.h @@ -108,10 +108,22 @@ * * This macro is used to indicate that a variable is intentionally left unused * in the code. It helps suppress compiler warnings about unused variables. + * It also protecting against actual use of the "unused" variable. * - * @param x The variable to mark as unused. */ -#define UNUSED(x) (void)(x) +#define UNUSED __attribute__((unused)) \ + __attribute__((deprecated ("parameter declared as UNUSED"))) + + +/** + * @brief mark a variable as potentially unused to suppress compiler warnings. + * + * This macro is used to indicate that a variable may be intentionally left unused + * in the code. It helps suppress compiler warnings about unused variables. + * It does *not* protect against the actual use of the "unused" variables. + */ + +#define MAYBE_UNUSED __attribute__((__unused__)) #endif /* COMPILER_H */ diff --git a/lib/decompress/decmp.c b/lib/decompress/decmp.c index b233bfe6bfd8cc75edd5d208d79a94ed0102b075..68b53b1b7d4e9eeb11189155140759fc5ba718b0 100644 --- a/lib/decompress/decmp.c +++ b/lib/decompress/decmp.c @@ -73,22 +73,19 @@ struct decoder_setup { * @brief decode the next unary code word in the bitstream * * @param dec a pointer to a bit_decoder context - * @param unused_1 this parameter is not used - * @param unused_2 this parameter is not used + * @param m this parameter is not used + * @param log2_m this parameter is not used * @note: Can be used to decode a code word with compression parameter m = 1 (log2_m = 0) * * @returns the decoded value */ -static __inline uint32_t unary_decoder(struct bit_decoder *dec, uint32_t unused_1, - uint32_t unused_2) +static __inline uint32_t unary_decoder(struct bit_decoder *dec, uint32_t m UNUSED, + uint32_t log2_m UNUSED) { uint32_t const decoded_cw = bit_peek_leading_ones(dec); /* decode unary coding */ uint32_t const cw_len = decoded_cw + 1; /* Number of 1's + following 0 */ - UNUSED(unused_1); /* we don't need this parameter */ - UNUSED(unused_2); /* and this parameter */ - bit_consume_bits(dec, cw_len); return decoded_cw;