diff options
author | Caio Oliveira <caio.oliveira@intel.com> | 2023-09-18 02:19:21 -0700 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-09-25 17:26:17 +0000 |
commit | 1486742b26943c65f21867969309cbc970d363dd (patch) | |
tree | ffaff42e207d24f677427396257eb214e83cf1c4 /src/util/ralloc.c | |
parent | 63ab9855114ebde337e7ea99e1a93659717339b7 (diff) | |
download | mesa-1486742b26943c65f21867969309cbc970d363dd.tar.gz mesa-1486742b26943c65f21867969309cbc970d363dd.tar.bz2 mesa-1486742b26943c65f21867969309cbc970d363dd.zip |
util: Remove usages of linear_realloc()
Note that for linear allocator, the realloc will always
allocate new memory. In both cases that realloc was used,
the existing size was known, so we can just allocate
and do the copy ourselves.
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25280>
Diffstat (limited to 'src/util/ralloc.c')
-rw-r--r-- | src/util/ralloc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 9a59ec67887..a7ce0e424c8 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -1226,10 +1226,12 @@ linear_vasprintf_rewrite_tail(linear_ctx *ctx, char **str, size_t *start, new_length = u_printf_length(fmt, args); - ptr = linear_realloc(ctx, *str, *start + new_length + 1); + ptr = linear_alloc_child(ctx, *start + new_length + 1); if (unlikely(ptr == NULL)) return false; + memcpy(ptr, *str, *start); + vsnprintf(ptr + *start, new_length + 1, fmt, args); *str = ptr; *start += new_length; @@ -1245,10 +1247,11 @@ linear_cat(linear_ctx *ctx, char **dest, const char *str, unsigned n) assert(dest != NULL && *dest != NULL); existing_length = strlen(*dest); - both = linear_realloc(ctx, *dest, existing_length + n + 1); + both = linear_alloc_child(ctx, existing_length + n + 1); if (unlikely(both == NULL)) return false; + memcpy(both, *dest, existing_length); memcpy(both + existing_length, str, n); both[existing_length + n] = '\0'; |