From: Kevin Day Date: Sat, 25 Apr 2020 04:12:27 +0000 (-0500) Subject: Bugfix: conversion of char to utf character is not working X-Git-Tag: 0.5.0~336 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=6d0bf775ad858a8523dcbf1a0b9afbdd13608164;p=fll Bugfix: conversion of char to utf character is not working This is the result of a simple typo, the 'to' should be a 'from' in the f_macro_utf_character_*_char_* calls. Add additional safety masks to the f_macro_utf_character_*_char_* macros. --- diff --git a/level_0/f_utf/c/utf.c b/level_0/f_utf/c/utf.c index f5c8578..e9f050e 100644 --- a/level_0/f_utf/c/utf.c +++ b/level_0/f_utf/c/utf.c @@ -2827,26 +2827,25 @@ extern "C" { return f_status_set_error(f_failure); } - *character_utf = 0; - *character_utf |= f_macro_utf_character_to_char_1(character[0]); + *character_utf = f_macro_utf_character_from_char_1(character[0]); if (width < 2) { return f_none; } - *character_utf |= f_macro_utf_character_to_char_2(character[1]); + *character_utf |= f_macro_utf_character_from_char_2(character[1]); if (width == 2) { return f_none; } - *character_utf |= f_macro_utf_character_to_char_3(character[2]); + *character_utf |= f_macro_utf_character_from_char_3(character[2]); if (width == 3) { return f_none; } - *character_utf |= f_macro_utf_character_to_char_4(character[3]); + *character_utf |= f_macro_utf_character_from_char_4(character[3]); return f_none; } diff --git a/level_0/f_utf/c/utf.h b/level_0/f_utf/c/utf.h index d711f70..78115a8 100644 --- a/level_0/f_utf/c/utf.h +++ b/level_0/f_utf/c/utf.h @@ -127,10 +127,10 @@ extern "C" { #define f_macro_utf_character_to_char_3(character) (((character) & f_utf_character_mask_char_3) >> 8) // grab third byte. #define f_macro_utf_character_to_char_4(character) ((character) & f_utf_character_mask_char_4) // grab fourth byte. - #define f_macro_utf_character_from_char_1(character) ((character) << 24) // shift the first byte. - #define f_macro_utf_character_from_char_2(character) ((character) << 16) // shift the second byte. - #define f_macro_utf_character_from_char_3(character) ((character) << 8) // shift the third byte. - #define f_macro_utf_character_from_char_4(character) ((character)) // shift the fourth byte. + #define f_macro_utf_character_from_char_1(character) (((character) << 24) & f_utf_character_mask_char_1) // shift to first byte. + #define f_macro_utf_character_from_char_2(character) (((character) << 16) & f_utf_character_mask_char_2) // shift to second byte. + #define f_macro_utf_character_from_char_3(character) (((character) << 8) & f_utf_character_mask_char_3) // shift to third byte. + #define f_macro_utf_character_from_char_4(character) ((character) & f_utf_character_mask_char_4) // shift to fourth byte. #define f_macro_utf_character_width(character) (f_macro_utf_byte_width(f_macro_utf_character_to_char_1(character))) #define f_macro_utf_character_width_is(character) (f_macro_utf_byte_width_is(f_macro_utf_character_to_char_1(character)))