Commit dfd26951 authored by Marc Horowitz's avatar Marc Horowitz Committed by Sara Golemon

Check array get for < 0

Summary: dynamic's integer type is signed, so make sure array indices
are not negative.

(See https://our.intern.facebook.com/intern/tasks/?t=7445055)

Reviewed By: @Gownta

Differential Revision: D2145689
parent 1137f4b8
......@@ -185,7 +185,7 @@ dynamic const& dynamic::at(dynamic const& idx) const {
if (!idx.isInt()) {
throw TypeError("int64", idx.type());
}
if (idx >= parray->size()) {
if (idx < 0 || idx >= parray->size()) {
throw std::out_of_range("out of range in dynamic array");
}
return (*parray)[idx.asInt()];
......
......@@ -157,6 +157,7 @@ TEST(Dynamic, ArrayBasics) {
EXPECT_EQ(array.at(1), 2);
EXPECT_EQ(array.at(2), 3);
EXPECT_ANY_THROW(array.at(-1));
EXPECT_ANY_THROW(array.at(3));
array.push_back("foo");
......
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