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}
This commit is contained in:
parent
cfbd16172f
commit
78030950fa
@ -48,7 +48,7 @@ struct Production {
|
||||
|
||||
WasmOpcode opcode() const { return static_cast<WasmOpcode>(*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; }
|
||||
};
|
||||
|
||||
@ -611,7 +611,7 @@ class LR_WasmDecoder : public Decoder {
|
||||
return;
|
||||
}
|
||||
|
||||
if (trees_.size() < retcount) {
|
||||
if (static_cast<int>(trees_.size()) < retcount) {
|
||||
error(limit_, nullptr,
|
||||
"ImplicitReturn expects %d arguments, only %d remain", retcount,
|
||||
static_cast<int>(trees_.size()));
|
||||
@ -998,7 +998,7 @@ class LR_WasmDecoder : public Decoder {
|
||||
FunctionSig* sig = FunctionSigOperand(p->pc(), &index, &len);
|
||||
USE(sig);
|
||||
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;
|
||||
}
|
||||
p->tree->node = builder_->CallDirect(index, buffer);
|
||||
@ -1017,7 +1017,7 @@ class LR_WasmDecoder : public Decoder {
|
||||
if (p->done() && build()) {
|
||||
uint32_t count = p->tree->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;
|
||||
}
|
||||
p->tree->node = builder_->CallIndirect(index, buffer);
|
||||
@ -1169,7 +1169,9 @@ class LR_WasmDecoder : public Decoder {
|
||||
} else if (to->effect != from->effect) {
|
||||
uint32_t count = builder_->InputCount(merge);
|
||||
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;
|
||||
to->effect = builder_->EffectPhi(count, effects, merge);
|
||||
}
|
||||
@ -1182,7 +1184,9 @@ class LR_WasmDecoder : public Decoder {
|
||||
} else if (tnode != fnode) {
|
||||
uint32_t count = builder_->InputCount(merge);
|
||||
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;
|
||||
to->locals[i] = builder_->Phi(function_env_->GetLocalType(i), count,
|
||||
vals, merge);
|
||||
@ -1203,7 +1207,7 @@ class LR_WasmDecoder : public Decoder {
|
||||
} else if (tnode != fnode) {
|
||||
uint32_t count = builder_->InputCount(merge);
|
||||
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;
|
||||
return builder_->Phi(type, count, vals, merge);
|
||||
}
|
||||
@ -1430,7 +1434,7 @@ std::ostream& operator<<(std::ostream& os, const Tree& tree) {
|
||||
}
|
||||
PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode()));
|
||||
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 << ", ";
|
||||
os << *tree.children[i];
|
||||
}
|
||||
@ -1571,6 +1575,8 @@ int OpcodeArity(FunctionEnv* env, const byte* pc) {
|
||||
FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE)
|
||||
#undef DECLARE_OPCODE_CASE
|
||||
}
|
||||
UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
|
@ -35,8 +35,10 @@ struct FunctionEnv {
|
||||
bool IsValidLocal(uint32_t index) { return index < total_locals; }
|
||||
uint32_t GetLocalCount() { return total_locals; }
|
||||
LocalType GetLocalType(uint32_t index) {
|
||||
if (index < sig->parameter_count()) return sig->GetParam(index);
|
||||
index -= sig->parameter_count();
|
||||
if (index < static_cast<uint32_t>(sig->parameter_count())) {
|
||||
return sig->GetParam(index);
|
||||
}
|
||||
index -= static_cast<uint32_t>(sig->parameter_count());
|
||||
if (index < local_int32_count) return kAstI32;
|
||||
index -= local_int32_count;
|
||||
if (index < local_int64_count) return kAstI64;
|
||||
|
@ -198,8 +198,8 @@ class Decoder {
|
||||
error_msg_.Reset(nullptr);
|
||||
} else {
|
||||
result.error_code = kSuccess;
|
||||
result.val = val;
|
||||
}
|
||||
result.val = val;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
|
||||
new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_);
|
||||
auto var_index = new uint16_t[locals_.size()];
|
||||
IndexVars(e, var_index);
|
||||
const byte* start = body_.data();
|
||||
const byte* start = &body_[0];
|
||||
const byte* end = start + body_.size();
|
||||
size_t local_index = 0;
|
||||
for (size_t i = 0; i < body_.size();) {
|
||||
@ -282,7 +282,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
|
||||
if (HasName()) {
|
||||
uint32_t name_offset = static_cast<uint32_t>(*body - buffer);
|
||||
EmitUint32(header, name_offset);
|
||||
std::memcpy(*body, name_.data(), name_.size());
|
||||
std::memcpy(*body, &name_[0], name_.size());
|
||||
(*body) += name_.size();
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
|
||||
|
||||
if (!external_) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -329,7 +329,7 @@ void WasmDataSegmentEncoder::Serialize(byte* buffer, byte** header,
|
||||
EmitUint32(header, static_cast<uint32_t>(data_.size()));
|
||||
EmitUint8(header, 1); // init
|
||||
|
||||
std::memcpy(*body, data_.data(), data_.size());
|
||||
std::memcpy(*body, &data_[0], data_.size());
|
||||
(*body) += data_.size();
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ void WasmModuleBuilder::AddDataSegment(WasmDataSegmentEncoder* data) {
|
||||
|
||||
|
||||
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->parameter_count() < b->parameter_count()) return -1;
|
||||
@ -493,7 +493,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
|
||||
if (sizes.body_size > 0) sizes.Add(1, 0);
|
||||
|
||||
ZoneVector<uint8_t> buffer_vector(sizes.total(), zone);
|
||||
byte* buffer = buffer_vector.data();
|
||||
byte* buffer = &buffer_vector[0];
|
||||
byte* header = buffer;
|
||||
byte* body = buffer + sizes.header_size;
|
||||
|
||||
|
@ -135,7 +135,7 @@ class WasmModuleBuilder : public ZoneObject {
|
||||
|
||||
private:
|
||||
struct CompareFunctionSigs {
|
||||
int operator()(FunctionSig* a, FunctionSig* b);
|
||||
int operator()(FunctionSig* a, FunctionSig* b) const;
|
||||
};
|
||||
typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap;
|
||||
|
||||
|
@ -371,7 +371,8 @@ class ModuleDecoder : public Decoder {
|
||||
str << "in function #" << func_num << ": ";
|
||||
// TODO(titzer): add function name for the user?
|
||||
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);
|
||||
char* buffer = new char[len];
|
||||
strncpy(buffer, raw, len);
|
||||
@ -387,7 +388,7 @@ class ModuleDecoder : public Decoder {
|
||||
// the offset is within bounds and advances.
|
||||
uint32_t offset(const char* name = nullptr) {
|
||||
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");
|
||||
}
|
||||
return offset;
|
||||
|
Loading…
Reference in New Issue
Block a user