aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arguments.c4
-rw-r--r--cmd-show-options.c2
-rw-r--r--tmux.h1
-rw-r--r--utf8.c14
4 files changed, 18 insertions, 3 deletions
diff --git a/arguments.c b/arguments.c
index c4c8e891..5ac51ddc 100644
--- a/arguments.c
+++ b/arguments.c
@@ -162,7 +162,7 @@ args_print(struct args *args)
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
if (entry->value[strcspn(entry->value, quoted)] != '\0')
flags |= VIS_DQ;
- stravis(&escaped, entry->value, flags);
+ utf8_stravis(&escaped, entry->value, flags);
if (flags & VIS_DQ)
args_print_add(&buf, &len, "\"%s\"", escaped);
else
@@ -178,7 +178,7 @@ args_print(struct args *args)
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
flags |= VIS_DQ;
- stravis(&escaped, args->argv[i], flags);
+ utf8_stravis(&escaped, args->argv[i], flags);
if (flags & VIS_DQ)
args_print_add(&buf, &len, "\"%s\"", escaped);
else
diff --git a/cmd-show-options.c b/cmd-show-options.c
index 5929e915..f7df2b11 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -105,7 +105,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
if (args_has(self->args, 'v'))
cmdq_print(item, "%s", value);
else if (options_isstring(o)) {
- stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
+ utf8_stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
cmdq_print(item, "%s \"%s\"", name, escaped);
free(escaped);
} else
diff --git a/tmux.h b/tmux.h
index 322547b0..eb1660dd 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2295,6 +2295,7 @@ enum utf8_state utf8_append(struct utf8_data *, u_char);
enum utf8_state utf8_combine(const struct utf8_data *, wchar_t *);
enum utf8_state utf8_split(wchar_t, struct utf8_data *);
int utf8_strvis(char *, const char *, size_t, int);
+int utf8_stravis(char **, const char *, int);
char *utf8_sanitize(const char *);
size_t utf8_strlen(const struct utf8_data *);
u_int utf8_strwidth(const struct utf8_data *, ssize_t);
diff --git a/utf8.c b/utf8.c
index 5ab2127a..ea8c99a2 100644
--- a/utf8.c
+++ b/utf8.c
@@ -193,6 +193,20 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag)
return (dst - start);
}
+/* Same as utf8_strvis but allocate the buffer. */
+int
+utf8_stravis(char **dst, const char *src, int flag)
+{
+ char *buf;
+ int len;
+
+ buf = xreallocarray(NULL, 4, strlen(src) + 1);
+ len = utf8_strvis(buf, src, strlen(src), flag);
+
+ *dst = xrealloc(buf, len + 1);
+ return (len);
+}
+
/*
* Sanitize a string, changing any UTF-8 characters to '_'. Caller should free
* the returned string. Anything not valid printable ASCII or UTF-8 is