X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fralloc.c;h=9526011b83674079815a21b744187c593480e689;hb=82b39f352142a91ad98ae84f313287eb14197c90;hp=01719c888b1023b958a58957ec2dcdd3d96ca798;hpb=33f0f68d590a460f84a0df0de10f29c4a582d7e7;p=mesa.git diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 01719c888b1..9526011b836 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -109,6 +109,18 @@ ralloc_context(const void *ctx) void * ralloc_size(const void *ctx, size_t size) +{ + /* ralloc_size was originally implemented using calloc, which meant some + * code accidentally relied on its zero filling behavior. + * + * TODO: Make ralloc_size not zero fill memory, and cleanup any code that + * should instead be using rzalloc. + */ + return rzalloc_size(ctx, size); +} + +void * +rzalloc_size(const void *ctx, size_t size) { void *block = calloc(1, size + sizeof(ralloc_header)); ralloc_header *info; @@ -128,15 +140,6 @@ ralloc_size(const void *ctx, size_t size) return PTR_FROM_HEADER(info); } -void * -rzalloc_size(const void *ctx, size_t size) -{ - void *ptr = ralloc_size(ctx, size); - if (likely(ptr != NULL)) - memset(ptr, 0, size); - return ptr; -} - /* helper function - assumes ptr != NULL */ static void * resize(void *ptr, size_t size) @@ -293,6 +296,7 @@ ralloc_adopt(const void *new_ctx, void *old_ctx) /* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */ child->next = new_info->child; + child->parent = new_info; new_info->child = old_info->child; old_info->child = NULL; } @@ -359,10 +363,7 @@ ralloc_strndup(const void *ctx, const char *str, size_t max) if (unlikely(str == NULL)) return NULL; - n = strlen(str); - if (n > max) - n = max; - + n = strnlen(str, max); ptr = ralloc_array(ctx, char, n + 1); memcpy(ptr, str, n); ptr[n] = '\0'; @@ -502,6 +503,7 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, if (unlikely(*str == NULL)) { // Assuming a NULL context is probably bad, but it's expected behavior. *str = ralloc_vasprintf(NULL, fmt, args); + *start = strlen(*str); return true; }