authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-06-29 02:30:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-29 13:19:39-04:00
log7a2b0cc9c44c9ad426e6f0b1a65b746b7535e35d
tree33645711e6369de4b51f0f9ac931ccf2e9358705
parent4b7e04f75aef8da6d2f95977cee69cd9b3b440a5

fix stack escape in add_source_file()


1 files changed, 7 insertions(+), 8 deletions(-)

src/analyze.cpp+7-8
......@@ -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);