Skip to content

Commit 7a2b0cc

Browse files
mikdusanandrewrk
authored andcommitted
fix stack escape in add_source_file()
1 parent 4b7e04f commit 7a2b0cc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/analyze.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,22 +3896,21 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
38963896
Buf *pkg_root_src_dir = &package->root_src_dir;
38973897
Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1);
38983898

3899-
Buf namespace_name = BUF_INIT;
3900-
buf_init_from_buf(&namespace_name, &package->pkg_path);
3899+
Buf *namespace_name = buf_create_from_buf(&package->pkg_path);
39013900
if (source_kind == SourceKindNonRoot) {
39023901
assert(buf_starts_with_buf(resolved_path, &resolved_root_src_dir));
3903-
if (buf_len(&namespace_name) != 0) {
3904-
buf_append_char(&namespace_name, NAMESPACE_SEP_CHAR);
3902+
if (buf_len(namespace_name) != 0) {
3903+
buf_append_char(namespace_name, NAMESPACE_SEP_CHAR);
39053904
}
39063905
// The namespace components are obtained from the relative path to the
39073906
// source directory
39083907
if (buf_len(&noextname) > buf_len(&resolved_root_src_dir)) {
39093908
// Skip the trailing separator
3910-
buf_append_mem(&namespace_name,
3909+
buf_append_mem(namespace_name,
39113910
buf_ptr(&noextname) + buf_len(&resolved_root_src_dir) + 1,
39123911
buf_len(&noextname) - buf_len(&resolved_root_src_dir) - 1);
39133912
}
3914-
buf_replace(&namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR);
3913+
buf_replace(namespace_name, ZIG_OS_SEP_CHAR, NAMESPACE_SEP_CHAR);
39153914
}
39163915
Buf *bare_name = buf_alloc();
39173916
os_path_extname(src_basename, bare_name, nullptr);
@@ -3922,7 +3921,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
39223921
root_struct->line_offsets = tokenization.line_offsets;
39233922
root_struct->path = resolved_path;
39243923
root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
3925-
ZigType *import_entry = get_root_container_type(g, buf_ptr(&namespace_name), bare_name, root_struct);
3924+
ZigType *import_entry = get_root_container_type(g, buf_ptr(namespace_name), bare_name, root_struct);
39263925
if (source_kind == SourceKindRoot) {
39273926
assert(g->root_import == nullptr);
39283927
g->root_import = import_entry;
@@ -3966,7 +3965,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
39663965
}
39673966

39683967
TldContainer *tld_container = allocate<TldContainer>(1);
3969-
init_tld(&tld_container->base, TldIdContainer, &namespace_name, VisibModPub, root_node, nullptr);
3968+
init_tld(&tld_container->base, TldIdContainer, namespace_name, VisibModPub, root_node, nullptr);
39703969
tld_container->type_entry = import_entry;
39713970
tld_container->decls_scope = import_entry->data.structure.decls_scope;
39723971
g->resolve_queue.append(&tld_container->base);

0 commit comments

Comments
 (0)