diff options
author | Alan Modra <amodra@gmail.com> | 2022-05-12 11:38:05 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-05-12 11:49:45 +0930 |
commit | fa445221958a9b8c8c4a804a339bc54cedfd83b9 (patch) | |
tree | 724c913d8833d1c5a69e0e003b60ba090177968c /binutils/ar.c | |
parent | a2d8448d1db6b052303dbbd576be1c00128e1bc6 (diff) | |
download | gdb-fa445221958a9b8c8c4a804a339bc54cedfd83b9.zip gdb-fa445221958a9b8c8c4a804a339bc54cedfd83b9.tar.gz gdb-fa445221958a9b8c8c4a804a339bc54cedfd83b9.tar.bz2 |
PR29142, segv in ar with empty archive and libdeps specified
PR 29142
* ar.c (main): Properly handle libdeps for zero file_count.
Diffstat (limited to 'binutils/ar.c')
-rw-r--r-- | binutils/ar.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/binutils/ar.c b/binutils/ar.c index 0d4c7cf..6f3f1d6 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -894,14 +894,16 @@ main (int argc, char **argv) being operated on. We shouldn't use 1st slot, but we want to avoid having to search all the way to the end of an archive with a large number of members at link time. */ - new_files = xmalloc ((file_count + 2) * sizeof (char *)); - new_files[0] = files[0]; - new_files[1] = LIBDEPS; - for (i = 1; i < file_count; i++) - new_files[i+1] = files[i]; - file_count = ++i; + new_files = xmalloc ((file_count + 2) * sizeof (*new_files)); + if (file_count) + { + new_files[0] = files[0]; + memcpy (new_files + 1, files, file_count * sizeof (*files)); + } + new_files[file_count != 0] = LIBDEPS; + file_count++; + new_files[file_count] = NULL; files = new_files; - files[i] = NULL; } switch (operation) |