Skip to content

Commit

Permalink
fix #4714:
Browse files Browse the repository at this point in the history
invalid range check for SetMapSquareTerrainType()
  • Loading branch information
abma committed Mar 25, 2015
1 parent f0a87fb commit 3f927da
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,8 @@ int LuaSyncedCtrl::SetMapSquareTerrainType(lua_State* L)
const int hx = int(luaL_checkfloat(L, 1) / SQUARE_SIZE);
const int hz = int(luaL_checkfloat(L, 2) / SQUARE_SIZE);

if ((hx < 0) || (hx > mapDims.mapx) || (hz < 0) || (hz > mapDims.mapy)) {
if ((hx < 0) || (hx >= mapDims.mapx) || (hz < 0) || (hz >= mapDims.mapy)) {
luaL_error(L, "Out of range: x = %d z = %d!", hx, hz);
return 0;
}

Expand Down

4 comments on commit 3f927da

@abma
Copy link
Contributor Author

@abma abma commented on 3f927da Mar 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats prefered in such a case: silently accept invalid input or give an error message?

in this case: is the error message ok or silently ignore the invalid values?

i guess i miss a common rule for the lua api, how to handle errors.

(i know, i've asked the same/similar question some time ago, but still i'm unsure when to do what)

@gajop
Copy link
Member

@gajop gajop commented on 3f927da Mar 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message please! Otherwise the user will just waste time trying to find what's wrong.

@abma
Copy link
Contributor Author

@abma abma commented on 3f927da Mar 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gajop
Copy link
Member

@gajop gajop commented on 3f927da Mar 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is synced Lua and entirely in the responsibility of the content devs.

Please sign in to comment.