Skip to content

Commit

Permalink
fix boundary check
Browse files Browse the repository at this point in the history
  • Loading branch information
aco4 committed Dec 19, 2024
1 parent 0d580d2 commit 4d036c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/wzmaplib/src/map_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, structure, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for structure", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for structure", direction);
sd.direction = static_cast<uint16_t>(direction);
auto modules = QuickJS_GetUint32(ctx, structure, "modules");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, modules < static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()), "Invalid modules (%" PRIu32 ") for structure", modules);
Expand Down Expand Up @@ -360,7 +360,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, droid, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for droid", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for droid", direction);
sd.direction = static_cast<uint16_t>(direction);
auto player = QuickJS_GetInt32(ctx, droid, "player");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, sd.player >= -1 && sd.player < MAX_PLAYERS, "Invalid player (%d) for droid", (int)sd.player);
Expand Down Expand Up @@ -392,7 +392,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, feature, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for feature", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for feature", direction);
sd.direction = static_cast<uint16_t>(direction);
mapFeatures->push_back(std::move(sd));
}
Expand Down

0 comments on commit 4d036c0

Please sign in to comment.