Ver código fonte

Merge pull request #330 from rwhitworth/rwhitworth-patch-3

fix uint32_t to char conversions in utf8_encode()
Marco Bambini 5 anos atrás
pai
commit
de32af6add
1 arquivos alterados com 10 adições e 10 exclusões
  1. 10 10
      src/utils/gravity_utils.c

+ 10 - 10
src/utils/gravity_utils.c

@@ -496,37 +496,37 @@ uint32_t utf8_encode(char *buffer, uint32_t value) {
     
     if (value <= 0x7f) {
         // single byte (i.e. fits in ASCII).
-        *bytes = value & 0x7f;
+        *bytes = (char)(value & 0x7f);
         return 1;
     }
     
     if (value <= 0x7ff) {
         // two byte sequence: 110xxxxx 10xxxxxx.
-        *bytes = 0xc0 | ((value & 0x7c0) >> 6);
+        *bytes = (char)(0xc0 | ((value & 0x7c0) >> 6));
         ++bytes;
-        *bytes = 0x80 | (value & 0x3f);
+        *bytes = (char)(0x80 | (value & 0x3f));
         return 2;
     }
     
     if (value <= 0xffff) {
         // three byte sequence: 1110xxxx 10xxxxxx 10xxxxxx.
-        *bytes = 0xe0 | ((value & 0xf000) >> 12);
+        *bytes = (char)(0xe0 | ((value & 0xf000) >> 12));
         ++bytes;
-        *bytes = 0x80 | ((value & 0xfc0) >> 6);
+        *bytes = (char)(0x80 | ((value & 0xfc0) >> 6));
         ++bytes;
-        *bytes = 0x80 | (value & 0x3f);
+        *bytes = (char)(0x80 | (value & 0x3f));
         return 3;
     }
     
     if (value <= 0x10ffff) {
         // four byte sequence: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx.
-        *bytes = 0xf0 | ((value & 0x1c0000) >> 18);
+        *bytes = (char)(0xf0 | ((value & 0x1c0000) >> 18));
         ++bytes;
-        *bytes = 0x80 | ((value & 0x3f000) >> 12);
+        *bytes = (char)(0x80 | ((value & 0x3f000) >> 12));
         ++bytes;
-        *bytes = 0x80 | ((value & 0xfc0) >> 6);
+        *bytes = (char)(0x80 | ((value & 0xfc0) >> 6));
         ++bytes;
-        *bytes = 0x80 | (value & 0x3f);
+        *bytes = (char)(0x80 | (value & 0x3f));
         return 4;
     }