aboutsummaryrefslogtreecommitdiffstats
path: root/malloc
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-09-18 09:26:00 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-09-25 18:04:22 -0700
commit5f9f31ad129d97e6fc548954c9b97e27dd332600 (patch)
treeb7f30d51192c046e0d23b6a04346d6549c9cb24f /malloc
parentccf970c7a77e86f4f5ef8ecc5e637114b1c0136a (diff)
downloadtermbaud-5f9f31ad129d97e6fc548954c9b97e27dd332600.tar.gz
termbaud-5f9f31ad129d97e6fc548954c9b97e27dd332600.tar.xz
termbaud-5f9f31ad129d97e6fc548954c9b97e27dd332600.zip
scratch_buffer: use union for internal buffer
Problem reported by Florian Weimer [1] and solution suggested by Andreas Schwab [2]. It also set the same buffer size independent of architecture max_align_t size. Checked on x86_64-linux-gnu and i686-linux-gnu. * lib/malloc/scratch_buffer.h (struct scratch_buffer): Use an union instead of a max_align_t array for __space, so that __space is the same size on all platforms. * malloc/scratch_buffer_grow_preserve.c (__libc_scratch_buffer_grow_preserve): Likewise. [1] https://sourceware.org/ml/libc-alpha/2017-09/msg00693.html [2] https://sourceware.org/ml/libc-alpha/2017-09/msg00695.html
Diffstat (limited to 'malloc')
-rw-r--r--malloc/scratch_buffer_grow_preserve.c4
-rw-r--r--malloc/tst-scratch_buffer.c2
2 files changed, 3 insertions, 3 deletions
diff --git a/malloc/scratch_buffer_grow_preserve.c b/malloc/scratch_buffer_grow_preserve.c
index 9268615311f..59a922b8a9e 100644
--- a/malloc/scratch_buffer_grow_preserve.c
+++ b/malloc/scratch_buffer_grow_preserve.c
@@ -30,14 +30,14 @@ __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
size_t new_length = 2 * buffer->length;
void *new_ptr;
- if (buffer->data == buffer->__space)
+ if (buffer->data == buffer->__space.__c)
{
/* Move buffer to the heap. No overflow is possible because
buffer->length describes a small buffer on the stack. */
new_ptr = malloc (new_length);
if (new_ptr == NULL)
return false;
- memcpy (new_ptr, buffer->__space, buffer->length);
+ memcpy (new_ptr, buffer->__space.__c, buffer->length);
}
else
{
diff --git a/malloc/tst-scratch_buffer.c b/malloc/tst-scratch_buffer.c
index 5c9f3442ae8..86447b62303 100644
--- a/malloc/tst-scratch_buffer.c
+++ b/malloc/tst-scratch_buffer.c
@@ -59,7 +59,7 @@ array_size_must_fail (size_t a, size_t b)
pass, a, b);
return false;
}
- if (buf.data != buf.__space)
+ if (buf.data != buf.__space.__c)
{
printf ("scratch_buffer_set_array_size did not free: %d %zu %zu\n",
pass, a, b);