From: Michael Tremer Date: Sat, 30 Sep 2023 10:25:16 +0000 (+0000) Subject: cli: Properly crash if we are not handling a CLI argument X-Git-Tag: 0.9.30~1595 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=817f755756ca9714dd7c158a265f59fae3f150f5;p=pakfire.git cli: Properly crash if we are not handling a CLI argument Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 24a9db311..5122c4ef7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -426,6 +426,8 @@ noinst_LTLIBRARIES += \ libcli.la libcli_la_SOURCES = \ + src/cli/lib/assert.c \ + src/cli/lib/assert.h \ src/cli/lib/build.c \ src/cli/lib/build.h \ src/cli/lib/check.c \ diff --git a/src/cli/lib/assert.c b/src/cli/lib/assert.c new file mode 100644 index 000000000..dfd67e4f7 --- /dev/null +++ b/src/cli/lib/assert.c @@ -0,0 +1,31 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include + +#include "assert.h" + +void __assert_unreachable(const char* file, const char* function, unsigned int line) { + fprintf(stderr, "Code should not have been reached in %s at %s:%u. Aborting.\n", + file, function, line); + + abort(); +} diff --git a/src/cli/lib/assert.h b/src/cli/lib/assert.h new file mode 100644 index 000000000..39d1e753e --- /dev/null +++ b/src/cli/lib/assert.h @@ -0,0 +1,29 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CLI_ASSERT_H +#define PAKFIRE_CLI_ASSERT_H + +void __assert_unreachable(const char* file, const char* function, unsigned int line); + +#define assert_unreachable() \ + __assert_unreachable(__FILE__, __FUNCTION__, __LINE__) + +#endif /* PAKFIRE_CLI_ASSERT_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index e2c04fbf9..ea2603770 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -28,6 +28,7 @@ #include #include +#include "lib/assert.h" #include "lib/build.h" #include "lib/clean.h" #include "lib/command.h" @@ -166,7 +167,7 @@ static int parse_argv(struct config* config, int argc, char* argv[]) { break; default: - break; + assert_unreachable(); } } diff --git a/src/cli/pakfire.c b/src/cli/pakfire.c index d25657867..1cdf9dc0d 100644 --- a/src/cli/pakfire.c +++ b/src/cli/pakfire.c @@ -26,6 +26,7 @@ #include +#include "lib/assert.h" #include "lib/clean.h" #include "lib/command.h" #include "lib/info.h" @@ -188,7 +189,7 @@ static int parse_argv(struct config* config, int argc, char* argv[]) { break; default: - break; + assert_unreachable(); } }