]> code.delx.au - pulseaudio/blobdiff - src/pulse/utf8.c
core: Fix uninit pointer read in protocol-native
[pulseaudio] / src / pulse / utf8.c
index 9dddf4a3f3ee8b0191409d4aaa3d14d843c79c6c..afefe80c703bba7fbae1b9fe8040e6f8d1438642 100644 (file)
 
 #define FILTER_CHAR '_'
 
-static inline pa_bool_t is_unicode_valid(uint32_t ch) {
+static inline bool is_unicode_valid(uint32_t ch) {
 
     if (ch >= 0x110000) /* End of unicode space */
-        return FALSE;
+        return false;
     if ((ch & 0xFFFFF800) == 0xD800) /* Reserved area for UTF-16 */
-        return FALSE;
+        return false;
     if ((ch >= 0xFDD0) && (ch <= 0xFDEF)) /* Reserved */
-        return FALSE;
+        return false;
     if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */
-        return FALSE;
+        return false;
 
-    return TRUE;
+    return true;
 }
 
-static inline pa_bool_t is_continuation_char(uint8_t ch) {
+static inline bool is_continuation_char(uint8_t ch) {
     if ((ch & 0xc0) != 0x80) /* 10xxxxxx */
-        return FALSE;
-    return TRUE;
+        return false;
+    return true;
 }
 
 static inline void merge_continuation_char(uint32_t *u_ch, uint8_t ch) {
@@ -148,12 +148,9 @@ ONE_REMAINING:
 
             if (o) {
                 memcpy(o, last, (size_t) size);
-                o += size - 1;
+                o += size;
             }
 
-            if (o)
-                o++;
-
             continue;
 
 error:
@@ -252,11 +249,16 @@ char* pa_locale_to_utf8 (const char *str) {
 
 char* pa_utf8_to_locale (const char *str) {
     pa_assert(str);
-    return NULL;
+
+    return pa_ascii_filter(str);
 }
 
 char* pa_locale_to_utf8 (const char *str) {
     pa_assert(str);
+
+    if (pa_utf8_valid(str))
+        return pa_xstrdup(str);
+
     return NULL;
 }