diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-10-06 22:10:26 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-10-06 22:11:21 +0200 |
commit | 3881725904473cd9fdbd3e60cd1de2010f14d767 (patch) | |
tree | acb491873cd73ab9924d7ae0776e9add3da94208 | |
parent | 6c364dc99766bfd3bd86cd262db37b1a766dca1e (diff) | |
download | tdv-3881725904473cd9fdbd3e60cd1de2010f14d767.tar.gz tdv-3881725904473cd9fdbd3e60cd1de2010f14d767.tar.xz tdv-3881725904473cd9fdbd3e60cd1de2010f14d767.zip |
tabfile: remember to check UTF-8, glibize
-rw-r--r-- | src/tabfile.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/tabfile.c b/src/tabfile.c index 0bcbff3..10700b0 100644 --- a/src/tabfile.c +++ b/src/tabfile.c @@ -31,7 +31,7 @@ #include "utils.h" static gboolean -set_data_error (GError **error, const char *message) +set_data_error (GError **error, const gchar *message) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, message); return FALSE; @@ -40,11 +40,11 @@ set_data_error (GError **error, const char *message) static const gchar escapes[256] = { ['n'] = '\n', ['t'] = '\t', ['\\'] = '\\' }; static gboolean -inplace_unescape (char *line, GError **error) +inplace_unescape (gchar *line, GError **error) { gboolean escape = FALSE; - char *dest = line; - for (char *src = line; *src; src++) + gchar *dest = line; + for (gchar *src = line; *src; src++) { if (escape) { @@ -65,12 +65,14 @@ inplace_unescape (char *line, GError **error) } static gboolean -import_line (Generator *generator, char *line, size_t len, GError **error) +import_line (Generator *generator, gchar *line, gsize len, GError **error) { if (!len) return TRUE; + if (!g_utf8_validate_len (line, len, NULL)) + return set_data_error (error, "not valid UTF-8"); - char *separator = strchr (line, '\t'); + gchar *separator = strchr (line, '\t'); if (!separator) return set_data_error (error, "keyword separator not found"); @@ -79,7 +81,7 @@ import_line (Generator *generator, char *line, size_t len, GError **error) // The index wouldn't be sorted correctly with our method return set_data_error (error, "escapes not allowed in keywords"); - char *newline = strpbrk (separator, "\r\n"); + gchar *newline = strpbrk (separator, "\r\n"); if (newline) *newline = 0; @@ -95,8 +97,8 @@ import_line (Generator *generator, char *line, size_t len, GError **error) static gboolean transform (FILE *fsorted, Generator *generator, GError **error) { - char *line = NULL; - size_t size = 0, ln = 1; + gchar *line = NULL; + gsize size = 0, ln = 1; for (ssize_t read; (read = getline (&line, &size, fsorted)) >= 0; ln++) if (!import_line (generator, line, read, error)) break; |