2025-07-29 10:18 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0003823Spring engineLuapublic2013-06-01 18:57
Reporterabma 
Assigned Toabma 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target Version95.0Fixed in Version 
Summary0003823: LuaBitOps.cpp contains some uncommented stuff (weirdness)
Descriptionhttps://github.com/spring/spring/blob/develop/rts/Lua/LuaBitOps.cpp#L11

and it uses for all operations unsigned int & masks all results to 0x00FFFFFF.
Additional Informationcan the patch be applied?

imo the mask is only there to make all results >0
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon 0001-simplify-math.bit_-allow-32-bit.patch (2,621 bytes) 2013-06-01 17:18 -
    From d47d17d02aae5f31a21723ed32df8f8ef7e61e0b Mon Sep 17 00:00:00 2001
    From: abma <spring@abma.de>
    Date: Sat, 1 Jun 2013 17:09:10 +0200
    Subject: [PATCH] simplify math.bit_* / allow 32 bit
    
    ---
     rts/Lua/LuaBitOps.cpp | 36 ++++++++++++++----------------------
     1 file changed, 14 insertions(+), 22 deletions(-)
    
    diff --git a/rts/Lua/LuaBitOps.cpp b/rts/Lua/LuaBitOps.cpp
    index a2403be..a875173 100644
    --- a/rts/Lua/LuaBitOps.cpp
    +++ b/rts/Lua/LuaBitOps.cpp
    @@ -8,8 +8,6 @@
     #include "LuaUtils.h"
     
     
    -const int mask = 0x00FFFFFF; // 2^24
    -
     
     /******************************************************************************/
     /******************************************************************************/
    @@ -28,61 +26,55 @@ bool LuaBitOps::PushEntries(lua_State* L)
     /******************************************************************************/
     /******************************************************************************/
     
    -static inline unsigned int luaL_checkuint(lua_State* L, int index)
    -{
    -	return (unsigned int)luaL_checkint(L, index);
    -}
    -
    -
     int LuaBitOps::bit_or(lua_State* L)
     {
    -	unsigned int result = 0x00000000;
    +	int result = 0x00000000;
     	for (int i = 1; !lua_isnone(L, i); i++) {
    -		result = result | luaL_checkuint(L, i);
    +		result = result | luaL_checkint(L, i);
     	}
    -	lua_pushnumber(L, result & mask);
    +	lua_pushinteger(L, result);
     	return 1;
     }
     
     
     int LuaBitOps::bit_and(lua_State* L)
     {
    -	unsigned int result = 0xFFFFFFFF;
    +	int result = 0xFFFFFFFF;
     	for (int i = 1; !lua_isnone(L, i); i++) {
    -		result = result & luaL_checkuint(L, i);
    +		result = result & luaL_checkint(L, i);
     	}
    -	lua_pushnumber(L, result & mask);
    +	lua_pushinteger(L, result);
     	return 1;
     }
     
     
     int LuaBitOps::bit_xor(lua_State* L)
     {
    -	unsigned int result = 0x00000000;
    +	int result = 0x00000000;
     	for (int i = 1; !lua_isnone(L, i); i++) {
    -		result = result ^ luaL_checkuint(L, i);
    +		result = result ^ luaL_checkint(L, i);
     	}
    -	lua_pushnumber(L, result & mask);
    +	lua_pushinteger(L, result);
     	return 1;
     }
     
     
     int LuaBitOps::bit_inv(lua_State* L)
     {
    -	const unsigned int result = ~luaL_checkuint(L, 1);
    -	lua_pushnumber(L, result & mask);
    +	const int result = ~luaL_checkint(L, 1);
    +	lua_pushinteger(L, result);
     	return 1;
     }
     
     
     int LuaBitOps::bit_bits(lua_State* L)
     {
    -	unsigned int result = 0x00000000;
    +	int result = 0x00000000;
     	for (int i = 1; !lua_isnone(L, i); i++) {
    -		const int bit = (unsigned int)luaL_checkint(L, i);
    +		const int bit = luaL_checkint(L, i);
     		result = result | (1 << bit);
     	}
    -	lua_pushnumber(L, result & mask);
    +	lua_pushinteger(L, result);
     	return 1;
     }
     
    -- 
    1.8.1.2
    
    
    patch file icon 0001-simplify-math.bit_-allow-32-bit.patch (2,621 bytes) 2013-06-01 17:18 +

-Relationships
+Relationships

-Notes

~0010800

abma (administrator)

http://springrts.com/phpbb/viewtopic.php?f=12&t=30545

~0010801

Kloot (developer)

Last edited: 2013-06-01 18:22

View 2 revisions

"imo the mask is only there to make all results >0"

wrong...

1) spring's lua vm uses FLOATS as its number type which can only represent integer values up to 1<<24 exactly

2) lua_pushinteger IS THE SAME AS lua_pushnumber except with an explicit rather than an implicit cast

imo people without extensive low-level engine knowledge should just not touch these areas under any circumstance... sorry but it's simply too vulnerable

~0010802

abma (administrator)

>imo people without extensive low-level engine knowledge should just not touch these areas...

this is why i asked here :)
+Notes

-Issue History
Date Modified Username Field Change
2013-06-01 17:18 abma New Issue
2013-06-01 17:18 abma File Added: 0001-simplify-math.bit_-allow-32-bit.patch
2013-06-01 17:18 abma Status new => feedback
2013-06-01 18:02 abma Note Added: 0010800
2013-06-01 18:02 abma Status feedback => new
2013-06-01 18:20 Kloot Note Added: 0010801
2013-06-01 18:22 Kloot Note Edited: 0010801 View Revisions
2013-06-01 18:46 abma Changeset attached => spring develop a5ee0f9d
2013-06-01 18:46 abma Assigned To => abma
2013-06-01 18:46 abma Status new => resolved
2013-06-01 18:46 abma Resolution open => fixed
2013-06-01 18:57 abma Note Added: 0010802
+Issue History