gas: NEWS: Add the RISC-V features for 2.39
[binutils-gdb.git] / libiberty / xmemdup.c
index aa56f0bf572bb71a52967878ddd3774cd7c9c1d2..f2ed41f9b4d9c659dbec0eb7c84df9f77ffe6d65 100644 (file)
@@ -1,4 +1,4 @@
-/* xmemdup.c -- Duplicate a memory buffer, using xcalloc.
+/* xmemdup.c -- Duplicate a memory buffer, using xmalloc.
    This trivial function is in the public domain.
    Jeff Garzik, September 1999.  */
 
@@ -31,9 +31,11 @@ allocated, the remaining memory is zeroed.
 # endif
 #endif
 
-PTR
-xmemdup (const PTR input, size_t copy_size, size_t alloc_size)
+void *
+xmemdup (const void *input, size_t copy_size, size_t alloc_size)
 {
-  PTR output = xcalloc (1, alloc_size);
-  return (PTR) memcpy (output, input, copy_size);
+  void *output = xmalloc (alloc_size);
+  if (alloc_size > copy_size)
+    memset ((char *) output + copy_size, 0, alloc_size - copy_size);
+  return (void *) memcpy (output, input, copy_size);
 }