From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: <libc-alpha@sourceware.org>
Subject: [PATCH v2 4/4] Remove unused scratch_buffer_dupfree
Date: Fri, 28 Oct 2022 17:40:15 +0100 [thread overview]
Message-ID: <b5ca69f7dbecde4078d5367442016681f0f9524b.1666974807.git.szabolcs.nagy@arm.com> (raw)
In-Reply-To: <cover.1666974807.git.szabolcs.nagy@arm.com>
Turns out scratch_buffer_dupfree internal API was unused since
commit ef0700004bf0dccf493a5e8e21f71d9e7972ea9f
stdlib: Simplify buffer management in canonicalize
And the related test in malloc/tst-scratch_buffer had issues
so it's better to remove it completely.
---
v2: remove all reference to scratch_buffer_dupfree
---
include/scratch_buffer.h | 16 -------------
malloc/Makefile | 1 -
malloc/scratch_buffer_dupfree.c | 41 ---------------------------------
malloc/tst-scratch_buffer.c | 20 ----------------
4 files changed, 78 deletions(-)
delete mode 100644 malloc/scratch_buffer_dupfree.c
diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h
index e4c5c8a85d..a9bdcadec2 100644
--- a/include/scratch_buffer.h
+++ b/include/scratch_buffer.h
@@ -132,20 +132,4 @@ scratch_buffer_set_array_size (struct scratch_buffer *buffer,
(buffer, nelem, size));
}
-/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block,
- deallocating *BUFFER if it was heap-allocated. SIZE must be at
- most *BUFFER's size. Return NULL (setting errno) on memory
- exhaustion. */
-void *__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer,
- size_t size);
-libc_hidden_proto (__libc_scratch_buffer_dupfree)
-
-/* Alias for __libc_scratch_dupfree. */
-static __always_inline void *
-scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
-{
- void *r = __libc_scratch_buffer_dupfree (buffer, size);
- return __glibc_likely (r != NULL) ? r : NULL;
-}
-
#endif /* _SCRATCH_BUFFER_H */
diff --git a/malloc/Makefile b/malloc/Makefile
index 4e32de2a0b..211be75e36 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -123,7 +123,6 @@ tests-mcheck = $(filter-out $(tests-exclude-mcheck) $(tests-static), $(tests))
endif
routines = malloc mcheck mtrace obstack reallocarray \
- scratch_buffer_dupfree \
scratch_buffer_grow scratch_buffer_grow_preserve \
scratch_buffer_set_array_size \
dynarray_at_failure \
diff --git a/malloc/scratch_buffer_dupfree.c b/malloc/scratch_buffer_dupfree.c
deleted file mode 100644
index eb3b95c1b1..0000000000
--- a/malloc/scratch_buffer_dupfree.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Variable-sized buffer with on-stack default allocation.
- Copyright (C) 2020-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <libc-config.h>
-#endif
-
-#include <scratch_buffer.h>
-#include <string.h>
-
-void *
-__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size)
-{
- void *data = buffer->data;
- if (data == buffer->__space.__c)
- {
- void *copy = malloc (size);
- return copy != NULL ? memcpy (copy, data, size) : NULL;
- }
- else
- {
- void *copy = realloc (data, size);
- return copy != NULL ? copy : data;
- }
-}
-libc_hidden_def (__libc_scratch_buffer_dupfree)
diff --git a/malloc/tst-scratch_buffer.c b/malloc/tst-scratch_buffer.c
index 9fcb11ba2c..1f1e770486 100644
--- a/malloc/tst-scratch_buffer.c
+++ b/malloc/tst-scratch_buffer.c
@@ -151,26 +151,6 @@ 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;
}
--
2.25.1
next prev parent reply other threads:[~2022-10-28 16:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 16:39 [PATCH v2 0/4] patches from the morello port Szabolcs Nagy
2022-10-28 16:39 ` [PATCH v2 1/4] Fix OOB read in stdlib thousand grouping parsing [BZ #29727] Szabolcs Nagy
2022-11-02 15:20 ` Andreas Schwab
2022-10-28 16:40 ` [PATCH v2 2/4] Fix off-by-one OOB write in iconv/tst-iconv-mt Szabolcs Nagy
2022-10-28 16:40 ` [PATCH v2 3/4] Fix elf/tst-dlmopen-twice not to exhaust static TLS Szabolcs Nagy
2022-10-28 17:04 ` Florian Weimer
2022-10-28 16:40 ` Szabolcs Nagy [this message]
2022-10-28 17:06 ` [PATCH v2 4/4] Remove unused scratch_buffer_dupfree Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5ca69f7dbecde4078d5367442016681f0f9524b.1666974807.git.szabolcs.nagy@arm.com \
--to=szabolcs.nagy@arm.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).