basic/journal-importer: do not write non-unicode char to log
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 17 May 2018 08:04:24 +0000 (10:04 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 May 2018 11:04:18 +0000 (13:04 +0200)
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
src/basic/escape.h
src/basic/journal-importer.c

index fe951e3..2e605b2 100644 (file)
@@ -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) {
 
index 6893f01..b47052b 100644 (file)
@@ -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);
index 0c77167..81044b8 100644 (file)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 
 #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;
         }