From 5ef447c629f2a987a84666ae50b2f52c28a3c6b9 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 24 Apr 2025 13:44:33 +0200 Subject: [PATCH] additional error checking --- lib/include/edapi/error.h | 5 +++++ lib/src/journal/file.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/lib/include/edapi/error.h b/lib/include/edapi/error.h index b235020..afb7514 100644 --- a/lib/include/edapi/error.h +++ b/lib/include/edapi/error.h @@ -22,4 +22,9 @@ typedef enum { */ #define goto_if_error(r, l) do { if (ED_ERROR(r)) goto l; } while(0) +/** + * Return `r` if `b` is true. + */ +#define return_if_true(b, r) do { if (b) return r; } while(0) + #endif diff --git a/lib/src/journal/file.c b/lib/src/journal/file.c index 9438de9..ff8e1f2 100644 --- a/lib/src/journal/file.c +++ b/lib/src/journal/file.c @@ -63,6 +63,9 @@ EDErrorCode ed_journal_file_parse(EDJournalFile *file, char const *filename) gchar *timestamp = NULL; gchar *index = NULL; + return_if_true(file == NULL, ed_error_args); + return_if_true(S_EMPTY(filename), ed_error_args); + new_style = g_regex_new( "Journal\\.([\\dT\\-]+)\\.(\\d+)\\.log", 0, 0, NULL