summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utf8.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/common/utf8.c b/src/common/utf8.c
index 7f2e6f1..1d4cf13 100644
--- a/src/common/utf8.c
+++ b/src/common/utf8.c
@@ -54,10 +54,17 @@ bool yasl_utf8_validate(const char *str, size_t len)
char *yasl_utf8_sanitize_dup(const char *str)
{
- if (!str) return NULL;
+ if (unlikely(!str)) return NULL;
size_t len = strlen(str);
+ if (likely(yasl_utf8_validate(str, len))) {
+ char *out = malloc(len + 1);
+ if (unlikely(!out)) return NULL;
+ memcpy(out, str, len + 1);
+ return out;
+ }
+
char *out = malloc(len + 1);
- if (!out) return NULL;
+ if (unlikely(!out)) return NULL;
const unsigned char *p = (const unsigned char *)str;
size_t o = 0;