From 90be086a921c9d594d9b1b8795c9bd7afeb461b6 Mon Sep 17 00:00:00 2001 From: Fergus Henderson Date: Tue, 15 Oct 2024 12:43:21 +0100 Subject: [PATCH] Fix crash for TypeScript enum in substruct See https://github.com/google/flatbuffers/issues/8299. --- src/idl_gen_ts.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 41c05e3b887..e170514fdae 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -901,11 +901,15 @@ class TsGenerator : public BaseGenerator { std::string bare_file_path; std::string rel_file_path; - const auto &dep_comps = dependent.defined_namespace->components; - for (size_t i = 0; i < dep_comps.size(); i++) { - rel_file_path += i == 0 ? ".." : (kPathSeparator + std::string("..")); + if (dependent.defined_namespace) { + const auto &dep_comps = dependent.defined_namespace->components; + for (size_t i = 0; i < dep_comps.size(); i++) { + rel_file_path += i == 0 ? ".." : (kPathSeparator + std::string("..")); + } + if (dep_comps.size() == 0) { rel_file_path += "."; } + } else { + rel_file_path += ".."; } - if (dep_comps.size() == 0) { rel_file_path += "."; } bare_file_path += kPathSeparator +