[RESEND][PATCH] modutils: fix "warning: function may return address of local variable"

Tomas Paukrt tomaspaukrt at email.cz
Mon Dec 30 06:34:45 UTC 2024


GCC 14.2 complains that the function filename2modname may return the address of
the local variable local_modname. It is a false positive, but still it is better
to allocate the memory directly to reduce the size of this function.

Signed-off-by: Tomas Paukrt <tomaspaukrt at email.cz>
---
 modutils/modutils.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/modutils/modutils.c b/modutils/modutils.c
index cbff209..8be0378 100644
--- a/modutils/modutils.c
+++ b/modutils/modutils.c
@@ -94,14 +94,13 @@ int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim)
 
 char* FAST_FUNC filename2modname(const char *filename, char *modname)
 {
-	char local_modname[MODULE_NAME_LEN];
 	int i;
 	const char *from;
 
 	if (filename == NULL)
 		return NULL;
 	if (modname == NULL)
-		modname = local_modname;
+		modname = xmalloc(MODULE_NAME_LEN);
 	// Disabled since otherwise "modprobe dir/name" would work
 	// as if it is "modprobe name". It is unclear why
 	// 'basenamization' was here in the first place.
@@ -111,9 +110,6 @@ char* FAST_FUNC filename2modname(const char *filename, char *modname)
 		modname[i] = (from[i] == '-') ? '_' : from[i];
 	modname[i] = '\0';
 
-	if (modname == local_modname)
-		return xstrdup(modname);
-
 	return modname;
 }
 
-- 
2.7.4
 


More information about the busybox mailing list