Commit 78030950 authored by bradnelson's avatar bradnelson Committed by Commit bot

Fix several wasm warnings an a use after free.

Fixing several signed/unsigned comparison warnings for wasm.
Fixing a use after free involving ostringsteam::str()

R=ahaas@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1533593004

Cr-Commit-Position: refs/heads/master@{#32946}
parent cfbd1617
...@@ -48,7 +48,7 @@ struct Production { ...@@ -48,7 +48,7 @@ struct Production {
WasmOpcode opcode() const { return static_cast<WasmOpcode>(*pc()); } WasmOpcode opcode() const { return static_cast<WasmOpcode>(*pc()); }
const byte* pc() const { return tree->pc; } const byte* pc() const { return tree->pc; }
bool done() const { return index >= tree->count; } bool done() const { return index >= static_cast<int>(tree->count); }
Tree* last() const { return index > 0 ? tree->children[index - 1] : nullptr; } Tree* last() const { return index > 0 ? tree->children[index - 1] : nullptr; }
}; };
...@@ -611,7 +611,7 @@ class LR_WasmDecoder : public Decoder { ...@@ -611,7 +611,7 @@ class LR_WasmDecoder : public Decoder {
return; return;
} }
if (trees_.size() < retcount) { if (static_cast<int>(trees_.size()) < retcount) {
error(limit_, nullptr, error(limit_, nullptr,
"ImplicitReturn expects %d arguments, only %d remain", retcount, "ImplicitReturn expects %d arguments, only %d remain", retcount,
static_cast<int>(trees_.size())); static_cast<int>(trees_.size()));
...@@ -998,7 +998,7 @@ class LR_WasmDecoder : public Decoder { ...@@ -998,7 +998,7 @@ class LR_WasmDecoder : public Decoder {
FunctionSig* sig = FunctionSigOperand(p->pc(), &index, &len); FunctionSig* sig = FunctionSigOperand(p->pc(), &index, &len);
USE(sig); USE(sig);
buffer[0] = nullptr; // reserved for code object. buffer[0] = nullptr; // reserved for code object.
for (int i = 1; i < count; i++) { for (uint32_t i = 1; i < count; i++) {
buffer[i] = p->tree->children[i - 1]->node; buffer[i] = p->tree->children[i - 1]->node;
} }
p->tree->node = builder_->CallDirect(index, buffer); p->tree->node = builder_->CallDirect(index, buffer);
...@@ -1017,7 +1017,7 @@ class LR_WasmDecoder : public Decoder { ...@@ -1017,7 +1017,7 @@ class LR_WasmDecoder : public Decoder {
if (p->done() && build()) { if (p->done() && build()) {
uint32_t count = p->tree->count; uint32_t count = p->tree->count;
TFNode** buffer = builder_->Buffer(count); TFNode** buffer = builder_->Buffer(count);
for (int i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
buffer[i] = p->tree->children[i]->node; buffer[i] = p->tree->children[i]->node;
} }
p->tree->node = builder_->CallIndirect(index, buffer); p->tree->node = builder_->CallIndirect(index, buffer);
...@@ -1169,7 +1169,9 @@ class LR_WasmDecoder : public Decoder { ...@@ -1169,7 +1169,9 @@ class LR_WasmDecoder : public Decoder {
} else if (to->effect != from->effect) { } else if (to->effect != from->effect) {
uint32_t count = builder_->InputCount(merge); uint32_t count = builder_->InputCount(merge);
TFNode** effects = builder_->Buffer(count); TFNode** effects = builder_->Buffer(count);
for (int j = 0; j < count - 1; j++) effects[j] = to->effect; for (uint32_t j = 0; j < count - 1; j++) {
effects[j] = to->effect;
}
effects[count - 1] = from->effect; effects[count - 1] = from->effect;
to->effect = builder_->EffectPhi(count, effects, merge); to->effect = builder_->EffectPhi(count, effects, merge);
} }
...@@ -1182,7 +1184,9 @@ class LR_WasmDecoder : public Decoder { ...@@ -1182,7 +1184,9 @@ class LR_WasmDecoder : public Decoder {
} else if (tnode != fnode) { } else if (tnode != fnode) {
uint32_t count = builder_->InputCount(merge); uint32_t count = builder_->InputCount(merge);
TFNode** vals = builder_->Buffer(count); TFNode** vals = builder_->Buffer(count);
for (int j = 0; j < count - 1; j++) vals[j] = tnode; for (uint32_t j = 0; j < count - 1; j++) {
vals[j] = tnode;
}
vals[count - 1] = fnode; vals[count - 1] = fnode;
to->locals[i] = builder_->Phi(function_env_->GetLocalType(i), count, to->locals[i] = builder_->Phi(function_env_->GetLocalType(i), count,
vals, merge); vals, merge);
...@@ -1203,7 +1207,7 @@ class LR_WasmDecoder : public Decoder { ...@@ -1203,7 +1207,7 @@ class LR_WasmDecoder : public Decoder {
} else if (tnode != fnode) { } else if (tnode != fnode) {
uint32_t count = builder_->InputCount(merge); uint32_t count = builder_->InputCount(merge);
TFNode** vals = builder_->Buffer(count); TFNode** vals = builder_->Buffer(count);
for (int j = 0; j < count - 1; j++) vals[j] = tnode; for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode;
vals[count - 1] = fnode; vals[count - 1] = fnode;
return builder_->Phi(type, count, vals, merge); return builder_->Phi(type, count, vals, merge);
} }
...@@ -1430,7 +1434,7 @@ std::ostream& operator<<(std::ostream& os, const Tree& tree) { ...@@ -1430,7 +1434,7 @@ std::ostream& operator<<(std::ostream& os, const Tree& tree) {
} }
PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode())); PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode()));
if (tree.count > 0) os << "("; if (tree.count > 0) os << "(";
for (int i = 0; i < tree.count; i++) { for (uint32_t i = 0; i < tree.count; i++) {
if (i > 0) os << ", "; if (i > 0) os << ", ";
os << *tree.children[i]; os << *tree.children[i];
} }
...@@ -1571,6 +1575,8 @@ int OpcodeArity(FunctionEnv* env, const byte* pc) { ...@@ -1571,6 +1575,8 @@ int OpcodeArity(FunctionEnv* env, const byte* pc) {
FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE)
#undef DECLARE_OPCODE_CASE #undef DECLARE_OPCODE_CASE
} }
UNREACHABLE();
return 0;
} }
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
......
...@@ -35,8 +35,10 @@ struct FunctionEnv { ...@@ -35,8 +35,10 @@ struct FunctionEnv {
bool IsValidLocal(uint32_t index) { return index < total_locals; } bool IsValidLocal(uint32_t index) { return index < total_locals; }
uint32_t GetLocalCount() { return total_locals; } uint32_t GetLocalCount() { return total_locals; }
LocalType GetLocalType(uint32_t index) { LocalType GetLocalType(uint32_t index) {
if (index < sig->parameter_count()) return sig->GetParam(index); if (index < static_cast<uint32_t>(sig->parameter_count())) {
index -= sig->parameter_count(); return sig->GetParam(index);
}
index -= static_cast<uint32_t>(sig->parameter_count());
if (index < local_int32_count) return kAstI32; if (index < local_int32_count) return kAstI32;
index -= local_int32_count; index -= local_int32_count;
if (index < local_int64_count) return kAstI64; if (index < local_int64_count) return kAstI64;
......
...@@ -198,8 +198,8 @@ class Decoder { ...@@ -198,8 +198,8 @@ class Decoder {
error_msg_.Reset(nullptr); error_msg_.Reset(nullptr);
} else { } else {
result.error_code = kSuccess; result.error_code = kSuccess;
result.val = val;
} }
result.val = val;
return result; return result;
} }
......
...@@ -159,7 +159,7 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone, ...@@ -159,7 +159,7 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_); new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_);
auto var_index = new uint16_t[locals_.size()]; auto var_index = new uint16_t[locals_.size()];
IndexVars(e, var_index); IndexVars(e, var_index);
const byte* start = body_.data(); const byte* start = &body_[0];
const byte* end = start + body_.size(); const byte* end = start + body_.size();
size_t local_index = 0; size_t local_index = 0;
for (size_t i = 0; i < body_.size();) { for (size_t i = 0; i < body_.size();) {
...@@ -282,7 +282,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header, ...@@ -282,7 +282,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
if (HasName()) { if (HasName()) {
uint32_t name_offset = static_cast<uint32_t>(*body - buffer); uint32_t name_offset = static_cast<uint32_t>(*body - buffer);
EmitUint32(header, name_offset); EmitUint32(header, name_offset);
std::memcpy(*body, name_.data(), name_.size()); std::memcpy(*body, &name_[0], name_.size());
(*body) += name_.size(); (*body) += name_.size();
} }
...@@ -295,7 +295,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header, ...@@ -295,7 +295,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
if (!external_) { if (!external_) {
EmitUint16(header, static_cast<uint16_t>(body_.size())); EmitUint16(header, static_cast<uint16_t>(body_.size()));
std::memcpy(*header, body_.data(), body_.size()); std::memcpy(*header, &body_[0], body_.size());
(*header) += body_.size(); (*header) += body_.size();
} }
} }
...@@ -329,7 +329,7 @@ void WasmDataSegmentEncoder::Serialize(byte* buffer, byte** header, ...@@ -329,7 +329,7 @@ void WasmDataSegmentEncoder::Serialize(byte* buffer, byte** header,
EmitUint32(header, static_cast<uint32_t>(data_.size())); EmitUint32(header, static_cast<uint32_t>(data_.size()));
EmitUint8(header, 1); // init EmitUint8(header, 1); // init
std::memcpy(*body, data_.data(), data_.size()); std::memcpy(*body, &data_[0], data_.size());
(*body) += data_.size(); (*body) += data_.size();
} }
...@@ -367,7 +367,7 @@ void WasmModuleBuilder::AddDataSegment(WasmDataSegmentEncoder* data) { ...@@ -367,7 +367,7 @@ void WasmModuleBuilder::AddDataSegment(WasmDataSegmentEncoder* data) {
int WasmModuleBuilder::CompareFunctionSigs::operator()(FunctionSig* a, int WasmModuleBuilder::CompareFunctionSigs::operator()(FunctionSig* a,
FunctionSig* b) { FunctionSig* b) const {
if (a->return_count() < b->return_count()) return -1; if (a->return_count() < b->return_count()) return -1;
if (a->return_count() > b->return_count()) return 1; if (a->return_count() > b->return_count()) return 1;
if (a->parameter_count() < b->parameter_count()) return -1; if (a->parameter_count() < b->parameter_count()) return -1;
...@@ -493,7 +493,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const { ...@@ -493,7 +493,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
if (sizes.body_size > 0) sizes.Add(1, 0); if (sizes.body_size > 0) sizes.Add(1, 0);
ZoneVector<uint8_t> buffer_vector(sizes.total(), zone); ZoneVector<uint8_t> buffer_vector(sizes.total(), zone);
byte* buffer = buffer_vector.data(); byte* buffer = &buffer_vector[0];
byte* header = buffer; byte* header = buffer;
byte* body = buffer + sizes.header_size; byte* body = buffer + sizes.header_size;
......
...@@ -135,7 +135,7 @@ class WasmModuleBuilder : public ZoneObject { ...@@ -135,7 +135,7 @@ class WasmModuleBuilder : public ZoneObject {
private: private:
struct CompareFunctionSigs { struct CompareFunctionSigs {
int operator()(FunctionSig* a, FunctionSig* b); int operator()(FunctionSig* a, FunctionSig* b) const;
}; };
typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap; typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap;
......
...@@ -371,7 +371,8 @@ class ModuleDecoder : public Decoder { ...@@ -371,7 +371,8 @@ class ModuleDecoder : public Decoder {
str << "in function #" << func_num << ": "; str << "in function #" << func_num << ": ";
// TODO(titzer): add function name for the user? // TODO(titzer): add function name for the user?
str << result; str << result;
const char* raw = str.str().c_str(); std::string strval = str.str();
const char* raw = strval.c_str();
size_t len = strlen(raw); size_t len = strlen(raw);
char* buffer = new char[len]; char* buffer = new char[len];
strncpy(buffer, raw, len); strncpy(buffer, raw, len);
...@@ -387,7 +388,7 @@ class ModuleDecoder : public Decoder { ...@@ -387,7 +388,7 @@ class ModuleDecoder : public Decoder {
// the offset is within bounds and advances. // the offset is within bounds and advances.
uint32_t offset(const char* name = nullptr) { uint32_t offset(const char* name = nullptr) {
uint32_t offset = u32(name ? name : "offset"); uint32_t offset = u32(name ? name : "offset");
if (offset > (limit_ - start_)) { if (offset > static_cast<uint32_t>(limit_ - start_)) {
error(pc_ - sizeof(uint32_t), "offset out of bounds of module"); error(pc_ - sizeof(uint32_t), "offset out of bounds of module");
} }
return offset; return offset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment