aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2019-06-10 13:15:23 +0100
committerNick Clifton <nickc@redhat.com>2019-06-10 13:15:23 +0100
commit2e02f29632218fc24d71fbbefc368d551d0528a7 (patch)
tree3e0e6fe09179717daf06c0fa971259aabaaa8afa /binutils
parenta3972330f49f81b3bea64af0970d22f42ae56ec3 (diff)
downloadgdb-2e02f29632218fc24d71fbbefc368d551d0528a7.zip
gdb-2e02f29632218fc24d71fbbefc368d551d0528a7.tar.gz
gdb-2e02f29632218fc24d71fbbefc368d551d0528a7.tar.bz2
Tidy up ar_open by using asprintf to replace xmalloc and sprintf.
PR 24649 * arsup.c (ar_open): Use asprintf in place of xmalloc and sprintf.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/arsup.c11
2 files changed, 15 insertions, 2 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index c98ed94..b845cac 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-10 Christos Zoulas <christos@zoulas.com>
+
+ PR 24649
+ * arsup.c (ar_open): Use asprintf in place of xmalloc and
+ sprintf.
+
2019-06-03 Nick Clifton <nickc@redhat.com>
Revert:
diff --git a/binutils/arsup.c b/binutils/arsup.c
index 75549bb..0836496 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -149,13 +149,20 @@ maybequit (void)
void
ar_open (char *name, int t)
{
- char *tname = (char *) xmalloc (strlen (name) + 10);
+ char *tname;
const char *bname = lbasename (name);
real_name = name;
/* Prepend tmp- to the beginning, to avoid file-name clashes after
truncation on filesystems with limited namespaces (DOS). */
- sprintf (tname, "%.*stmp-%s", (int) (bname - name), name, bname);
+ if (asprintf (&tname, "%.*stmp-%s", (int) (bname - name), name, bname) == -1)
+ {
+ fprintf (stderr, _("%s: Can't allocate memory for temp name (%s)\n"),
+ program_name, strerror(errno));
+ maybequit ();
+ return;
+ }
+
obfd = bfd_openw (tname, NULL);
if (!obfd)