Hi Anton,

On Mon, 2025-02-03 at 14:45 +0100, Mark Wielaard wrote:
> So the code path where prefix != NULL also implies suffix != NULL.
> 
> Maybe the code needs a comment, check or assert to verify this?

I added an assert.

Pushed,

Mark
From 316077dd4b34c90f7e4c4228395a580e99239347 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <m...@klomp.org>
Date: Tue, 11 Feb 2025 14:46:44 +0100
Subject: [PATCH] elflint: process_file both prefix and suffix are NULL or both
 are non-NULL

Add an assert of this property to help static analyzers (or humans)
reading this code.

	* src/elflint.c (process_file): Add assert.

Signed-off-by: Mark Wielaard <m...@klomp.org>
---
 src/elflint.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/elflint.c b/src/elflint.c
index cdc6108d9287..a46682c757ea 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -252,6 +252,10 @@ process_file (int fd, Elf *elf, const char *prefix, const char *suffix,
 	char new_suffix[(suffix == NULL ? 0 : strlen (suffix)) + 2];
 	char *cp = new_prefix;
 
+	/* Either both prefix and suffix are NULL or both are non-NULL.  */
+	assert ((prefix == NULL && suffix == NULL)
+		|| (prefix != NULL && suffix != NULL));
+
 	/* Create the full name of the file.  */
 	if (prefix != NULL)
 	  {
-- 
2.48.1

Reply via email to