aboutsummaryrefslogtreecommitdiff
path: root/malloc/tst-scratch_buffer.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-12-28 09:50:23 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-01-05 11:33:16 -0300
commit448a256359e951fd2e81ccb2926e3f2b1d7a09de (patch)
treea0eb770538013c697f378a35cc035f033381d44f /malloc/tst-scratch_buffer.c
parent47f43160953677faf33853359ee7b973dc487139 (diff)
downloadglibc-448a256359e951fd2e81ccb2926e3f2b1d7a09de.zip
glibc-448a256359e951fd2e81ccb2926e3f2b1d7a09de.tar.gz
glibc-448a256359e951fd2e81ccb2926e3f2b1d7a09de.tar.bz2
malloc: Add scratch_buffer_dupfree
It returns a copy of the buffer up to a defined size. It will be used on realpath sync with gnulib.
Diffstat (limited to 'malloc/tst-scratch_buffer.c')
-rw-r--r--malloc/tst-scratch_buffer.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/malloc/tst-scratch_buffer.c b/malloc/tst-scratch_buffer.c
index 8ea07e8..6e521c7 100644
--- a/malloc/tst-scratch_buffer.c
+++ b/malloc/tst-scratch_buffer.c
@@ -16,7 +16,10 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <array_length.h>
#include <scratch_buffer.h>
+#include <support/check.h>
+#include <support/support.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@@ -148,8 +151,27 @@ do_test (void)
&& array_size_must_fail (4, ((size_t)-1) / 4)))
return 1;
}
+ {
+ struct scratch_buffer buf;
+ scratch_buffer_init (&buf);
+ memset (buf.data, '@', buf.length);
+
+ size_t sizes[] = { 16, buf.length, buf.length + 16 };
+ for (int i = 0; i < array_length (sizes); i++)
+ {
+ /* The extra size is unitialized through realloc. */
+ size_t l = sizes[i] > buf.length ? sizes[i] : buf.length;
+ void *r = scratch_buffer_dupfree (&buf, l);
+ void *c = xmalloc (l);
+ memset (c, '@', l);
+ TEST_COMPARE_BLOB (r, l, buf.data, l);
+ free (r);
+ free (c);
+ }
+
+ scratch_buffer_free (&buf);
+ }
return 0;
}
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>