fix off by one temp cstring and put objc names on permanent allocator to be safe

Fixes #4922
This commit is contained in:
Laytan Laats
2025-03-21 22:53:00 +01:00
parent 69b969ef7f
commit f85db012b8
2 changed files with 3 additions and 7 deletions

View File

@@ -2812,15 +2812,11 @@ gb_internal lbAddr lb_add_global_generated_with_name(lbModule *m, Type *type, lb
GB_ASSERT(type != nullptr);
type = default_type(type);
u8 *str = cast(u8 *)gb_alloc_array(temporary_allocator(), u8, name.len);
memcpy(str, name.text, name.len);
str[name.len] = 0;
Scope *scope = nullptr;
Entity *e = alloc_entity_variable(scope, make_token_ident(name), type);
lbValue g = {};
g.type = alloc_type_pointer(type);
g.value = LLVMAddGlobal(m->mod, lb_type(m, type), cast(char const *)str);
g.value = LLVMAddGlobal(m->mod, lb_type(m, type), alloc_cstring(temporary_allocator(), name));
if (value.value != nullptr) {
GB_ASSERT_MSG(LLVMIsConstant(value.value), LLVMPrintValueToString(value.value));
LLVMSetInitializer(g.value, value.value);