From b778252b4ab9b2a1ea6d01cab3057308e9af1f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 May 2018 10:04:24 +0200 Subject: [PATCH] basic/journal-importer: do not write non-unicode char to log The type of cescape_char() is changed to int to make it easier to use in "%.*s". We know the value is between 1 and 4, so size_t is overkill. --- src/basic/escape.c | 4 ++-- src/basic/escape.h | 2 +- src/basic/journal-importer.c | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/basic/escape.c b/src/basic/escape.c index fe951e3db8..2e605b2ebe 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -15,8 +15,8 @@ #include "macro.h" #include "utf8.h" -size_t cescape_char(char c, char *buf) { - char * buf_old = buf; +int cescape_char(char c, char *buf) { + char *buf_old = buf; switch (c) { diff --git a/src/basic/escape.h b/src/basic/escape.h index 6893f0199b..b47052b142 100644 --- a/src/basic/escape.h +++ b/src/basic/escape.h @@ -45,7 +45,7 @@ typedef enum EscapeStyle { char *cescape(const char *s); char *cescape_length(const char *s, size_t n); -size_t cescape_char(char c, char *buf); +int cescape_char(char c, char *buf); int cunescape(const char *s, UnescapeFlags flags, char **ret); int cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret); diff --git a/src/basic/journal-importer.c b/src/basic/journal-importer.c index 0c7716717f..81044b85fb 100644 --- a/src/basic/journal-importer.c +++ b/src/basic/journal-importer.c @@ -9,6 +9,7 @@ #include #include "alloc-util.h" +#include "escape.h" #include "fd-util.h" #include "io-util.h" #include "journal-file.h" @@ -233,7 +234,11 @@ static int get_data_newline(JournalImporter *imp) { assert(data); if (*data != '\n') { - log_error("expected newline, got '%c'", *data); + char buf[4]; + int l; + + l = cescape_char(*data, buf); + log_error("Expected newline, got '%.*s'", l, buf); return -EINVAL; }