aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-08-03 08:18:13 +0930
committerAlan Modra <amodra@gmail.com>2023-08-03 21:19:54 +0930
commit137f6bc0dabe209c1617fb396eb590e7b7ee8faa (patch)
tree2d6344704ee9abd7b006c51ca9bea6ecfc3bb12b
parente2e7c5261311fd7d557769a73e1fbc496cd56d23 (diff)
downloadgdb-137f6bc0dabe209c1617fb396eb590e7b7ee8faa.zip
gdb-137f6bc0dabe209c1617fb396eb590e7b7ee8faa.tar.gz
gdb-137f6bc0dabe209c1617fb396eb590e7b7ee8faa.tar.bz2
resrc: sprintf sanitizer null destination pointer
* resrc.c (read_rc_file): Use stpcpy rather than sprintf followed by strlen. Tidy.
-rw-r--r--binutils/resrc.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/binutils/resrc.c b/binutils/resrc.c
index 3ea9813..0d7a6e1 100644
--- a/binutils/resrc.c
+++ b/binutils/resrc.c
@@ -441,29 +441,23 @@ read_rc_file (const char *filename, const char *preprocessor,
{
char *edit, *dir;
- if (filename[0] == '/'
- || filename[0] == '\\'
- || filename[1] == ':')
- /* Absolute path. */
- edit = dir = xstrdup (filename);
- else
+ edit = dir = xmalloc (strlen (filename) + 3);
+ if (filename[0] != '/'
+ && filename[0] != '\\'
+ && filename[1] != ':')
{
/* Relative path. */
- edit = dir = xmalloc (strlen (filename) + 3);
- sprintf (dir, "./%s", filename);
+ *edit++ = '.';
+ *edit++ = '/';
}
+ edit = stpcpy (edit, filename);
/* Walk dir backwards stopping at the first directory separator. */
- edit += strlen (dir);
while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
- {
- --edit;
- edit[0] = 0;
- }
+ --edit;
/* Cut off trailing slash. */
- --edit;
- edit[0] = 0;
+ *--edit = 0;
/* Convert all back slashes to forward slashes. */
while ((edit = strchr (dir, '\\')) != NULL)