mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
_i18n_number_rewrite: Use struct scratch_buffer
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
2017-06-29 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* stdio-common/vfprintf.c (WORK_BUFFER_SIZE): Reduce size for
|
* stdio-common/vfprintf.c (WORK_BUFFER_SIZE): Reduce size for
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
#include <scratch_buffer.h>
|
||||||
|
|
||||||
#include "../locale/outdigits.h"
|
#include "../locale/outdigits.h"
|
||||||
#include "../locale/outdigitswc.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. */
|
/* Copy existing string so that nothing gets overwritten. */
|
||||||
CHAR_T *src;
|
CHAR_T *src;
|
||||||
bool use_alloca = __libc_use_alloca ((rear_ptr - w) * sizeof (CHAR_T));
|
struct scratch_buffer buffer;
|
||||||
if (__builtin_expect (use_alloca, true))
|
scratch_buffer_init (&buffer);
|
||||||
src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
|
if (!scratch_buffer_set_array_size (&buffer, 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.
|
/* If we cannot allocate the memory don't rewrite the string.
|
||||||
It is better than nothing. */
|
It is better than nothing. */
|
||||||
return w;
|
return w;
|
||||||
}
|
src = buffer.data;
|
||||||
|
|
||||||
CHAR_T *s = (CHAR_T *) __mempcpy (src, w,
|
CHAR_T *s = (CHAR_T *) __mempcpy (src, w,
|
||||||
(rear_ptr - w) * sizeof (CHAR_T));
|
(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)
|
scratch_buffer_free (&buffer);
|
||||||
free (src);
|
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user