summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2026-01-30 13:09:10 +0100
committerJean Boussier <jean.boussier@gmail.com>2026-01-30 15:24:48 +0100
commit9be01bc70dca0e727fe1f518ebae1f6f72405b84 (patch)
treef9a3d7b3e27b2b6ea8fa36492583bd8ab8d81eec
parent3c100019a4a1b0ef66db76ec3b14f63eac51dd4d (diff)
gc.c: also verify sized_xrealloc old size
-rw-r--r--gc/default/default.c7
-rw-r--r--parse.y2
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 { \