Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/support/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ T wasm::read_file(const std::string& filename, Flags::BinaryOption binary) {
<< "': Input file too large: " << insize
<< " bytes. Try rebuilding in 64-bit mode.";
}
T input(size_t(insize) + (binary == Flags::Binary ? 0 : 1), '\0');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here, this looks mysterious by itself I think...

// Zero-initialize the string or vector with the expected size.
T input(size_t(insize), '\0');
if (size_t(insize) == 0) {
return input;
}
Expand All @@ -82,8 +83,7 @@ T wasm::read_file(const std::string& filename, Flags::BinaryOption binary) {
// Truncate size to the number of ASCII characters actually read in text
// mode (which is generally less than the number of bytes on Windows, if
// \r\n line endings are present)
input.resize(chars + 1);
input[chars] = '\0';
input.resize(chars);
}
return input;
}
Expand Down
2 changes: 0 additions & 2 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,6 @@ int main(int argc, const char* argv[]) {
});
options.parse(argc, argv);

auto input(read_file<std::string>(options.extra["infile"], Flags::Text));

Module wasm;
options.applyFeatures(wasm);

Expand Down
2 changes: 0 additions & 2 deletions src/tools/wasm-metadce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,6 @@ int main(int argc, const char* argv[]) {
Fatal() << "no graph file provided.";
}

auto input(read_file<std::string>(options.extra["infile"], Flags::Text));

Module wasm;
options.applyFeatures(wasm);

Expand Down
3 changes: 1 addition & 2 deletions src/tools/wasm2js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,7 @@ int main(int argc, const char* argv[]) {
ModuleReader reader;
reader.read(input, wasm, "");
} else {
auto input(
read_file<std::vector<char>>(options.extra["infile"], Flags::Text));
auto input(read_file<std::string>(options.extra["infile"], Flags::Text));
if (options.debug) {
std::cerr << "s-parsing..." << std::endl;
}
Expand Down
3 changes: 1 addition & 2 deletions src/wasm/wasm-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ bool useNewWATParser = false;

static void readTextData(std::string& input, Module& wasm, IRProfile profile) {
if (useNewWATParser) {
std::string_view in(input.c_str());
if (auto parsed = WATParser::parseModule(wasm, in);
if (auto parsed = WATParser::parseModule(wasm, input);
auto err = parsed.getErr()) {
Fatal() << err->msg;
}
Expand Down