From: Kevin Day Date: Sun, 31 Dec 2023 02:33:33 +0000 (-0600) Subject: Update: Explicitly cast UTF conversion to/from to a uint32_t. X-Git-Tag: 0.6.8~1 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=fd3281c8f17214b0f4052b5c269db1b1070c2871;p=fll Update: Explicitly cast UTF conversion to/from to a uint32_t. If the type is changed or the defines are used with different types, then the shift operators may become problematic. Prevent this potential problem from happening through explicit casts to uint32_t. --- diff --git a/level_0/f_utf/c/utf/common.h b/level_0/f_utf/c/utf/common.h index 672a132..048ad93 100644 --- a/level_0/f_utf/c/utf/common.h +++ b/level_0/f_utf/c/utf/common.h @@ -196,15 +196,15 @@ extern "C" { #define F_utf_char_mask_char_3_be_d 0x0000ff00 // 0000 0000, 0000 0000, 1111 1111, 0000 0000 #define F_utf_char_mask_char_4_be_d 0x000000ff // 0000 0000, 0000 0000, 0000 0000, 1111 1111 - #define macro_f_utf_char_t_to_char_1_be(sequence) (((sequence) & F_utf_char_mask_char_1_be_d) >> 24) // Grab first byte. - #define macro_f_utf_char_t_to_char_2_be(sequence) (((sequence) & F_utf_char_mask_char_2_be_d) >> 16) // Grab second byte. - #define macro_f_utf_char_t_to_char_3_be(sequence) (((sequence) & F_utf_char_mask_char_3_be_d) >> 8) // Grab third byte. - #define macro_f_utf_char_t_to_char_4_be(sequence) ((sequence) & F_utf_char_mask_char_4_be_d) // Grab fourth byte. + #define macro_f_utf_char_t_to_char_1_be(sequence) ((uint32_t) ((sequence) & F_utf_char_mask_char_1_be_d) >> 24) // Grab first byte. + #define macro_f_utf_char_t_to_char_2_be(sequence) ((uint32_t) ((sequence) & F_utf_char_mask_char_2_be_d) >> 16) // Grab second byte. + #define macro_f_utf_char_t_to_char_3_be(sequence) ((uint32_t) ((sequence) & F_utf_char_mask_char_3_be_d) >> 8) // Grab third byte. + #define macro_f_utf_char_t_to_char_4_be(sequence) ((uint32_t) (sequence) & F_utf_char_mask_char_4_be_d) // Grab fourth byte. - #define macro_f_utf_char_t_from_char_1_be(sequence) (((sequence) << 24) & F_utf_char_mask_char_1_be_d) // Shift to first byte. - #define macro_f_utf_char_t_from_char_2_be(sequence) (((sequence) << 16) & F_utf_char_mask_char_2_be_d) // Shift to second byte. - #define macro_f_utf_char_t_from_char_3_be(sequence) (((sequence) << 8) & F_utf_char_mask_char_3_be_d) // Shift to third byte. - #define macro_f_utf_char_t_from_char_4_be(sequence) ((sequence) & F_utf_char_mask_char_4_be_d) // Shift to fourth byte. + #define macro_f_utf_char_t_from_char_1_be(sequence) ((((uint32_t) (sequence)) << 24) & F_utf_char_mask_char_1_be_d) // Shift to first byte. + #define macro_f_utf_char_t_from_char_2_be(sequence) ((((uint32_t) (sequence)) << 16) & F_utf_char_mask_char_2_be_d) // Shift to second byte. + #define macro_f_utf_char_t_from_char_3_be(sequence) ((((uint32_t) (sequence)) << 8) & F_utf_char_mask_char_3_be_d) // Shift to third byte. + #define macro_f_utf_char_t_from_char_4_be(sequence) (((uint32_t) (sequence)) & F_utf_char_mask_char_4_be_d) // Shift to fourth byte. // Little Endian. #define F_utf_char_mask_byte_1_le_d 0x000000ff // 0000 0000, 0000 0000, 0000 0000, 1111 1111 @@ -217,15 +217,15 @@ extern "C" { #define F_utf_char_mask_char_3_le_d 0x00ff0000 // 0000 0000, 1111 1111, 0000 0000, 0000 0000 #define F_utf_char_mask_char_4_le_d 0xff000000 // 1111 1111, 0000 0000, 0000 0000, 0000 0000 - #define macro_f_utf_char_t_to_char_1_le(sequence) ((sequence) & F_utf_char_mask_char_1_le_d) // Grab first byte. - #define macro_f_utf_char_t_to_char_2_le(sequence) (((sequence) & F_utf_char_mask_char_2_le_d) >> 8) // Grab second byte. - #define macro_f_utf_char_t_to_char_3_le(sequence) (((sequence) & F_utf_char_mask_char_3_le_d) >> 16) // Grab third byte. - #define macro_f_utf_char_t_to_char_4_le(sequence) (((sequence) & F_utf_char_mask_char_4_le_d) >> 24) // Grab fourth byte. + #define macro_f_utf_char_t_to_char_1_le(sequence) ((uint32_t) ((sequence) & F_utf_char_mask_char_1_le_d)) // Grab first byte. + #define macro_f_utf_char_t_to_char_2_le(sequence) (((uint32_t) ((sequence) & F_utf_char_mask_char_2_le_d)) >> 8) // Grab second byte. + #define macro_f_utf_char_t_to_char_3_le(sequence) (((uint32_t) ((sequence) & F_utf_char_mask_char_3_le_d)) >> 16) // Grab third byte. + #define macro_f_utf_char_t_to_char_4_le(sequence) (((uint32_t) ((sequence) & F_utf_char_mask_char_4_le_d)) >> 24) // Grab fourth byte. - #define macro_f_utf_char_t_from_char_1_le(sequence) ((sequence) & F_utf_char_mask_char_1_le_d) // Shift to first byte. - #define macro_f_utf_char_t_from_char_2_le(sequence) (((sequence) << 8) & F_utf_char_mask_char_2_le_d) // Shift to second byte. - #define macro_f_utf_char_t_from_char_3_le(sequence) (((sequence) << 16) & F_utf_char_mask_char_3_le_d) // Shift to third byte. - #define macro_f_utf_char_t_from_char_4_le(sequence) (((sequence) << 24) & F_utf_char_mask_char_4_le_d) // Shift to fourth byte. + #define macro_f_utf_char_t_from_char_1_le(sequence) (((uint32_t) (sequence) & F_utf_char_mask_char_1_le_d)) // Shift to first byte. + #define macro_f_utf_char_t_from_char_2_le(sequence) ((((uint32_t) (sequence) << 8) & F_utf_char_mask_char_2_le_d)) // Shift to second byte. + #define macro_f_utf_char_t_from_char_3_le(sequence) ((((uint32_t) (sequence) << 16) & F_utf_char_mask_char_3_le_d)) // Shift to third byte. + #define macro_f_utf_char_t_from_char_4_le(sequence) ((((uint32_t) (sequence) << 24) & F_utf_char_mask_char_4_le_d)) // Shift to fourth byte. #define F_utf_char_mask_byte_1_d F_utf_char_mask_byte_1_be_d #define F_utf_char_mask_byte_2_d F_utf_char_mask_byte_2_be_d