about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-06-29 09:34:45 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-06-29 09:34:45 +0200
commitcd00e12d31dd9de465a0d5f2677fa71bc2b12d80 (patch)
treee2e007f56d519a16dc57c8168049b0071e43d6f5
parent08d01cae60aa3966ed21e6ec70bbe9fef730e012 (diff)
downloadglibc-cd00e12d31dd9de465a0d5f2677fa71bc2b12d80.tar.gz
glibc-cd00e12d31dd9de465a0d5f2677fa71bc2b12d80.tar.xz
glibc-cd00e12d31dd9de465a0d5f2677fa71bc2b12d80.zip
_i18n_number_rewrite: Use struct scratch_buffer
-rw-r--r--ChangeLog5
-rw-r--r--stdio-common/_i18n_number.h23
2 files changed, 14 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index db0c4ad37e..67c5d07722 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-06-29  Florian Weimer  <fweimer@redhat.com>
 
+	* stdio-common/_i18n_number.h (_i18n_number_rewrite): Use struct
+	scratch_buffer.
+
+2017-06-29  Florian Weimer  <fweimer@redhat.com>
+
 	* stdio-common/vfprintf.c (WORK_BUFFER_SIZE): Reduce size for
 	wchar_t builds.
 
diff --git a/stdio-common/_i18n_number.h b/stdio-common/_i18n_number.h
index 080e8141b9..13d59365ff 100644
--- a/stdio-common/_i18n_number.h
+++ b/stdio-common/_i18n_number.h
@@ -19,6 +19,7 @@
 #include <stdbool.h>
 #include <wchar.h>
 #include <wctype.h>
+#include <scratch_buffer.h>
 
 #include "../locale/outdigits.h"
 #include "../locale/outdigitswc.h"
@@ -65,17 +66,13 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end)
 
   /* Copy existing string so that nothing gets overwritten.  */
   CHAR_T *src;
-  bool use_alloca = __libc_use_alloca ((rear_ptr - w) * sizeof (CHAR_T));
-  if (__builtin_expect (use_alloca, true))
-    src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
-  else
-    {
-      src = (CHAR_T *) malloc ((rear_ptr - w) * sizeof (CHAR_T));
-      if (src == NULL)
-	/* If we cannot allocate the memory don't rewrite the string.
-	   It is better than nothing.  */
-	return w;
-    }
+  struct scratch_buffer buffer;
+  scratch_buffer_init (&buffer);
+  if (!scratch_buffer_set_array_size (&buffer, rear_ptr - w, sizeof (CHAR_T)))
+    /* If we cannot allocate the memory don't rewrite the string.
+       It is better than nothing.  */
+    return w;
+  src = buffer.data;
 
   CHAR_T *s = (CHAR_T *) __mempcpy (src, w,
 				    (rear_ptr - w) * sizeof (CHAR_T));
@@ -110,8 +107,6 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end)
 	}
     }
 
-  if (! use_alloca)
-    free (src);
-
+  scratch_buffer_free (&buffer);
   return w;
 }