[1/2,applied] abicompat: Do not abort when abicompat is invoked without argument

Message ID 8733wvnr7t.fsf@seketeli.org
State New
Headers
Series [1/2,applied] abicompat: Do not abort when abicompat is invoked without argument |

Commit Message

Dodji Seketeli Aug. 3, 2026, 3:44 p.m. UTC
  Hello,

When abicompat is called without any argument, an ABG_ASSERT causes
the program to abort. This patch replaces that assertion with proper
error handling, displaying usage information and returning an
appropriate error code.

	* tools/abicompat.cc (main): Replace ABG_ASSERT on empty
	app_path with proper error handling that emits a message,
	displays usage help via argp_help, and returns
	ABIDIFF_USAGE_ERROR | ABIDIFF_ERROR.  When check_file fails for
	the application path, emit a descriptive error message
	indicating the file doesn't exist and display usage help before
	returning ABIDIFF_ERROR.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>

Applied to the master branch.

---
 tools/abicompat.cc | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Patch

diff --git a/tools/abicompat.cc b/tools/abicompat.cc
index 4546ca37..61c43679 100644
--- a/tools/abicompat.cc
+++ b/tools/abicompat.cc
@@ -971,9 +971,22 @@  main(int argc, char* argv[])
       return 1;
     }
 
-  ABG_ASSERT(!opts.app_path.empty());
+  if (opts.app_path.empty())
+    {
+      emit_prefix(argv[0], cerr)
+	<< "Expecting at least the path to an application binary\n";
+      argp_help(&abicompat_argp, stderr, ARGP_HELP_USAGE, argv[0]);
+      return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
+	    | abigail::tools_utils::ABIDIFF_ERROR);
+    }
+
   if (!abigail::tools_utils::check_file(opts.app_path, cerr, opts.prog_name))
-    return abigail::tools_utils::ABIDIFF_ERROR;
+    {
+      emit_prefix(argv[0], cerr)
+	<< "Application file " << opts.app_path << "doesn't exist\n";
+      argp_help(&abicompat_argp, stderr, ARGP_HELP_USAGE, argv[0]);
+      return abigail::tools_utils::ABIDIFF_ERROR;
+    }
 
   // Create the context of the diff
   diff_context_sptr ctxt = create_diff_context(opts);