From 4ad4e723aab36660a6dc8343537e5f33b21331e4 Mon Sep 17 00:00:00 2001 From: Dipin Hora Date: Wed, 5 Feb 2025 11:56:51 -0500 Subject: [PATCH] ubsan: fix buildflagset "applying non-zero offset to null pointer" ubsan doesn't like that buildflagset adds offsets to null pointers. This commit fixes things to ensure that buildflagset always has a valid text buffer to work with. Makes ubsan runtime errors such as the following go away: `runtime error: applying non-zero offset 11 to null pointer` --- src/libponyc/pkg/buildflagset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libponyc/pkg/buildflagset.c b/src/libponyc/pkg/buildflagset.c index b7a3cb08e5..0cb3397fd4 100644 --- a/src/libponyc/pkg/buildflagset.c +++ b/src/libponyc/pkg/buildflagset.c @@ -146,8 +146,9 @@ buildflagset_t* buildflagset_create() p->started_enum = false; p->flags = POOL_ALLOC(flagtab_t); flagtab_init(p->flags, 8); - p->text_buffer = NULL; - p->buffer_size = 0; + p->text_buffer = (char*)ponyint_pool_alloc_size(1); + p->buffer_size = 1; + p->text_buffer[0] = '\0'; return p; }