summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/support/file.cpp6
-rw-r--r--src/tools/wasm-ctor-eval.cpp2
-rw-r--r--src/tools/wasm-metadce.cpp2
-rw-r--r--src/tools/wasm2js.cpp3
-rw-r--r--src/wasm/wasm-io.cpp3
5 files changed, 5 insertions, 11 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp
index feb05e136..08b9e31af 100644
--- a/src/support/file.cpp
+++ b/src/support/file.cpp
@@ -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');
+ // Zero-initialize the string or vector with the expected size.
+ T input(size_t(insize), '\0');
if (size_t(insize) == 0) {
return input;
}
@@ -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;
}
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index fe3d42d09..a806333af 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -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);
diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp
index cd8c8546a..1b429a723 100644
--- a/src/tools/wasm-metadce.cpp
+++ b/src/tools/wasm-metadce.cpp
@@ -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);
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index 1c2606b6a..e5b949b90 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -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;
}
diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp
index 37d28ca4b..df1cc19f4 100644
--- a/src/wasm/wasm-io.cpp
+++ b/src/wasm/wasm-io.cpp
@@ -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;
}