summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-28 13:51:37 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-03-28 13:51:37 -0700
commit1a09f6d5162df5177cf7209f9898cfd5e6705b6c (patch)
treed60c8fcc48db008e6882c4e1503fbba61fed1fa0 /src/emscripten-optimizer
parent68e15c423d92dd69138702cc572e503a33b31782 (diff)
downloadbinaryen-1a09f6d5162df5177cf7209f9898cfd5e6705b6c.tar.gz
binaryen-1a09f6d5162df5177cf7209f9898cfd5e6705b6c.tar.bz2
binaryen-1a09f6d5162df5177cf7209f9898cfd5e6705b6c.zip
use strncpy #283
Diffstat (limited to 'src/emscripten-optimizer')
-rw-r--r--src/emscripten-optimizer/istring.h11
-rw-r--r--src/emscripten-optimizer/simple_ast.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/emscripten-optimizer/istring.h b/src/emscripten-optimizer/istring.h
index 498c7c27c..8e91d044d 100644
--- a/src/emscripten-optimizer/istring.h
+++ b/src/emscripten-optimizer/istring.h
@@ -72,8 +72,9 @@ struct IString {
} else {
auto existing = strings->find(s);
if (existing == strings->end()) {
- char *copy = (char*)malloc(strlen(s)+1); // XXX leaked
- strcpy(copy, s);
+ size_t len = strlen(s) + 1;
+ char *copy = (char*)malloc(len); // XXX leaked
+ strncpy(copy, s, len);
s = copy;
strings->insert(s);
} else {
@@ -147,9 +148,9 @@ class IStringSet : public std::unordered_set<IString> {
public:
IStringSet() {}
IStringSet(const char *init) { // comma-delimited list
- int size = strlen(init);
- char *curr = new char[size+1]; // leaked!
- strcpy(curr, init);
+ int size = strlen(init) + 1;
+ char *curr = new char[size]; // leaked!
+ strncpy(curr, init, size);
while (1) {
char *end = strchr(curr, ' ');
if (end) *end = 0;
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 73037815f..75b7987be 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -626,7 +626,7 @@ struct JSPrinter {
maybeSpace(*s);
int len = strlen(s);
ensure(len+1);
- strcpy(buffer + used, s);
+ strncpy(buffer + used, s, len+1);
used += len;
}