From 9be01bc70dca0e727fe1f518ebae1f6f72405b84 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 30 Jan 2026 13:09:10 +0100 Subject: gc.c: also verify sized_xrealloc old size --- gc/default/default.c | 7 ++++++- parse.y | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gc/default/default.c b/gc/default/default.c index aaf6f56092..a6572b6f4d 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -8270,7 +8270,7 @@ rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size) struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1; #if VERIFY_FREE_SIZE if (old_size && (old_size + sizeof(struct malloc_obj_info)) != info->size) { - rb_bug("buffer %p freed with size %lu, but was allocated with size %lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info)); + rb_bug("buffer %p freed with old_size=%lu, but was allocated with size=%lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info)); } #endif ptr = info; @@ -8379,6 +8379,11 @@ rb_gc_impl_realloc(void *objspace_ptr, void *ptr, size_t new_size, size_t old_si struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1; new_size += sizeof(struct malloc_obj_info); ptr = info; +#if VERIFY_FREE_SIZE + if (old_size && (old_size + sizeof(struct malloc_obj_info)) != info->size) { + rb_bug("buffer %p realloced with old_size=%lu, but was allocated with size=%lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info)); + } +#endif old_size = info->size; } #endif diff --git a/parse.y b/parse.y index 03dd1c6f92..7ca1197b37 100644 --- a/parse.y +++ b/parse.y @@ -1995,7 +1995,7 @@ parser_memhash(const void *ptr, long len) #define STRING_TERM_LEN(str) (1) #define STRING_TERM_FILL(str) (str->ptr[str->len] = '\0') #define PARSER_STRING_RESIZE_CAPA_TERM(p,str,capacity,termlen) do {\ - SIZED_REALLOC_N(str->ptr, char, (size_t)total + termlen, STRING_SIZE(str)); \ + REALLOC_N(str->ptr, char, (size_t)total + termlen); \ str->len = total; \ } while (0) #define STRING_SET_LEN(str, n) do { \ -- cgit v1.2.3