From dbe20d453d5e93bd0f1188a8851c6cf4fd230b26 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 11 Nov 2023 00:01:34 -0500 Subject: Extend path_append_ex to truncate compname, remove some strmemdupa remove some duplicated strings previously allocd off the stack just removing string duplications that are easily handled with truncation now available with path_append_ex() this also has an advantage of less stack used in worst case scenarios Change-Id: I3a43e33ef8a8c36599e4c6c036a0ccdd8ed0c883 --- firmware/common/file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'firmware/common/file.c') diff --git a/firmware/common/file.c b/firmware/common/file.c index 202410db81..2012e2ff80 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -1056,7 +1056,7 @@ int rename(const char *old, const char *new) FILE_ERROR(EINVAL, -4); } - const char * const oldname = strmemdupa(oldinfo.name, oldinfo.length); + //const char * const oldname = strmemdupa(oldinfo.name, oldinfo.length); const char * const newname = strmemdupa(newinfo.name, newinfo.length); bool is_overwrite = false; @@ -1076,7 +1076,8 @@ int rename(const char *old, const char *new) FILE_ERROR(ERRNO, rc * 10 - 5); } } - else if (!strcmp(newname, oldname)) /* case-only is ok */ + else if (!strncmp(newname, oldinfo.name, oldinfo.length) && /* case-only is ok */ + newname[oldinfo.length] == '\0') /* make sure of actual match */ { DEBUGF("No name change (success)\n"); rc = 0; -- cgit v1.2.3