Skip to content

Commit 0bcc0b3

Browse files
committed
[Fift] Fix an issue of FunC/Tolk WASM which truncated long fif output
As it turned out, PSTRING() created a buffer of 128K. If asm_code exceeded this buffer, it was truncated. I've just dropped PSTRING() from there in favor of std::string.
1 parent ebbab54 commit 0bcc0b3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crypto/fift/utils.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class MemoryFileLoader : public fift::FileLoader {
114114
std::map<std::string, std::string, std::less<>> files_;
115115
};
116116

117-
td::Result<fift::SourceLookup> create_source_lookup(std::string main, bool need_preamble = true, bool need_asm = true,
117+
td::Result<fift::SourceLookup> create_source_lookup(std::string&& main, bool need_preamble = true, bool need_asm = true,
118118
bool need_ton_util = true, bool need_lisp = true,
119119
bool need_w3_code = true, bool need_fift_ext = true,
120120
bool need_disasm = true, std::string dir = "") {
@@ -189,7 +189,7 @@ td::Result<fift::SourceLookup> run_fift(fift::SourceLookup source_lookup, std::o
189189
} // namespace
190190
td::Result<FiftOutput> mem_run_fift(std::string source, std::vector<std::string> args, std::string fift_dir) {
191191
std::stringstream ss;
192-
TRY_RESULT(source_lookup, create_source_lookup(source, true, true, true, true, true, true, true, fift_dir));
192+
TRY_RESULT(source_lookup, create_source_lookup(std::move(source), true, true, true, true, true, true, true, fift_dir));
193193
TRY_RESULT_ASSIGN(source_lookup, run_fift(std::move(source_lookup), &ss, true, std::move(args)));
194194
FiftOutput res;
195195
res.source_lookup = std::move(source_lookup);
@@ -207,16 +207,21 @@ td::Result<FiftOutput> mem_run_fift(SourceLookup source_lookup, std::vector<std:
207207
td::Result<fift::SourceLookup> create_mem_source_lookup(std::string main, std::string fift_dir, bool need_preamble,
208208
bool need_asm, bool need_ton_util, bool need_lisp,
209209
bool need_w3_code) {
210-
return create_source_lookup(main, need_preamble, need_asm, need_ton_util, need_lisp, need_w3_code, false, false,
210+
return create_source_lookup(std::move(main), need_preamble, need_asm, need_ton_util, need_lisp, need_w3_code, false, false,
211211
fift_dir);
212212
}
213213

214214
td::Result<td::Ref<vm::Cell>> compile_asm(td::Slice asm_code, std::string fift_dir, bool is_raw) {
215215
std::stringstream ss;
216-
TRY_RESULT(source_lookup,
217-
create_source_lookup(PSTRING() << "\"Asm.fif\" include\n " << (is_raw ? "<{" : "") << asm_code << "\n"
218-
<< (is_raw ? "}>c" : "") << " boc>B \"res\" B>file",
219-
true, true, true, false, false, false, false, fift_dir));
216+
std::string sb;
217+
sb.reserve(asm_code.size() + 100);
218+
sb.append("\"Asm.fif\" include\n ");
219+
sb.append(is_raw ? "<{" : "");
220+
sb.append(asm_code.data(), asm_code.size());
221+
sb.append(is_raw ? "}>c" : "");
222+
sb.append(" boc>B \"res\" B>file");
223+
224+
TRY_RESULT(source_lookup, create_source_lookup(std::move(sb), true, true, true, false, false, false, false, fift_dir));
220225
TRY_RESULT(res, run_fift(std::move(source_lookup), &ss));
221226
TRY_RESULT(boc, res.read_file("res"));
222227
return vm::std_boc_deserialize(std::move(boc.data));

0 commit comments

Comments
 (0)