]> Kevux Git Server - fll/commitdiff
Bugfix: conversion of char to utf character is not working
authorKevin Day <thekevinday@gmail.com>
Sat, 25 Apr 2020 04:12:27 +0000 (23:12 -0500)
committerKevin Day <thekevinday@gmail.com>
Sat, 25 Apr 2020 04:12:27 +0000 (23:12 -0500)
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.

level_0/f_utf/c/utf.c
level_0/f_utf/c/utf.h

index f5c857803f8f18f048a11a64122837b1129af4aa..e9f050e6ee7dfe0cf92a76f79a1832d6db130657 100644 (file)
@@ -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;
   }
index d711f704fc181b3043e3e5fb063caa21342bbb7e..78115a8ea5b1c30c84b01cdaa90dfbe631729234 100644 (file)
@@ -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)))