Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] casting pointer to 32-bit int, likely cause of Windows crashes #32

Open
qwertychouskie opened this issue Apr 3, 2019 · 2 comments
Assignees
Labels
Priority: P2 High priority T: Bug Something isn't working
Milestone

Comments

@qwertychouskie
Copy link
Member

qwerty@qwerty-Inspiron-3520:~/Eclipse/eclipse-workspace/Cubosphere/build-win$ make -j6
[  2%] Building C object lib/glew/CMakeFiles/glew.dir/src/glewinfo.c.obj
[  5%] Building C object lib/glew/CMakeFiles/glew.dir/src/glew.c.obj
[  8%] Linking C static library libglew.a
[  8%] Built target glew
[ 11%] Building CXX object CMakeFiles/cubosphere.dir/src/console.cpp.obj
[ 13%] Building CXX object CMakeFiles/cubosphere.dir/src/c3dobjects.cpp.obj
[ 16%] Building CXX object CMakeFiles/cubosphere.dir/src/cuboboxes.cpp.obj
[ 19%] Building CXX object CMakeFiles/cubosphere.dir/src/cuboactors.cpp.obj
[ 25%] Building CXX object CMakeFiles/cubosphere.dir/src/cubolevels.cpp.obj
[ 25%] Building CXX object CMakeFiles/cubosphere.dir/src/cuboenemies.cpp.obj
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp: In function ‘int LEVEL_FileBegin(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp:981:41: warning: cast from ‘FILE* {aka _iobuf*}’ to ‘long unsigned int’ loses precision [-fpermissive]
  unsigned long int i=(unsigned long int)f;
                                         ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp: In function ‘int LEVEL_FileWrite(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp:989:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp: In function ‘int LEVEL_FileData(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp:996:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp: In function ‘int LEVEL_FileEnd(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/cubolevels.cpp:1005:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
[ 27%] Building CXX object CMakeFiles/cubosphere.dir/src/cubopathfind.cpp.obj
[ 30%] Building CXX object CMakeFiles/cubosphere.dir/src/cuboutils.cpp.obj
[ 33%] Building CXX object CMakeFiles/cubosphere.dir/src/definitions.cpp.obj
[ 36%] Building CXX object CMakeFiles/cubosphere.dir/src/events.cpp.obj
[ 38%] Building CXX object CMakeFiles/cubosphere.dir/src/filesystem.cpp.obj
[ 41%] Building CXX object CMakeFiles/cubosphere.dir/src/fonts.cpp.obj
[ 44%] Building CXX object CMakeFiles/cubosphere.dir/src/game.cpp.obj
[ 47%] Building CXX object CMakeFiles/cubosphere.dir/src/globals.cpp.obj
[ 50%] Building CXX object CMakeFiles/cubosphere.dir/src/glutils.cpp.obj
[ 52%] Building CXX object CMakeFiles/cubosphere.dir/src/joystick.cpp.obj
[ 55%] Building CXX object CMakeFiles/cubosphere.dir/src/keyboard.cpp.obj
[ 58%] Building CXX object CMakeFiles/cubosphere.dir/src/log.cpp.obj
[ 61%] Building CXX object CMakeFiles/cubosphere.dir/src/luamodules.cpp.obj
[ 63%] Building CXX object CMakeFiles/cubosphere.dir/src/luautils.cpp.obj
[ 66%] Building CXX object CMakeFiles/cubosphere.dir/src/main.cpp.obj
[ 69%] Building CXX object CMakeFiles/cubosphere.dir/src/matrixutils.cpp.obj
[ 72%] Building CXX object CMakeFiles/cubosphere.dir/src/models.cpp.obj
[ 75%] Building CXX object CMakeFiles/cubosphere.dir/src/mouse.cpp.obj
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SAVE_Open(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:777:41: warning: cast from ‘FILE* {aka _iobuf*}’ to ‘long unsigned int’ loses precision [-fpermissive]
  unsigned long int i=(unsigned long int)f;
                                         ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SAVE_Write(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:785:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SAVE_Close(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:793:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SCORE_Open(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:828:41: warning: cast from ‘FILE* {aka _iobuf*}’ to ‘long unsigned int’ loses precision [-fpermissive]
  unsigned long int i=(unsigned long int)f;
                                         ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SCORE_Write(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:836:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::SCORE_Close(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:844:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::CONFIG_Open(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:1014:41: warning: cast from ‘FILE* {aka _iobuf*}’ to ‘long unsigned int’ loses precision [-fpermissive]
  unsigned long int i=(unsigned long int)f;
                                         ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::CONFIG_Write(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:1022:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp: In static member function ‘static int LuaCuboLib::CONFIG_Close(lua_State*)’:
/home/qwerty/Eclipse/eclipse-workspace/Cubosphere/src/luautils.cpp:1030:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  FILE *f=(FILE *)c;
                  ^
[ 77%] Building CXX object CMakeFiles/cubosphere.dir/src/posteffects.cpp.obj
[ 80%] Building CXX object CMakeFiles/cubosphere.dir/src/shaderutil.cpp.obj
[ 83%] Building CXX object CMakeFiles/cubosphere.dir/src/skyboxes.cpp.obj
[ 86%] Building CXX object CMakeFiles/cubosphere.dir/src/sounds.cpp.obj
[ 88%] Building CXX object CMakeFiles/cubosphere.dir/src/spriteutils.cpp.obj
[ 91%] Building CXX object CMakeFiles/cubosphere.dir/src/textures.cpp.obj
[ 94%] Building CXX object CMakeFiles/cubosphere.dir/src/themes.cpp.obj
[ 97%] Building CXX object CMakeFiles/cubosphere.dir/src/vectors.cpp.obj
[100%] Linking CXX executable bin/cubosphere.exe
[100%] Built target cubosphere
qwerty@qwerty-Inspiron-3520:~/Eclipse/eclipse-workspace/Cubosphere/build-win$ 

According to https://stackoverflow.com/a/11797049/4901968 this will cause instability. A quick google shows https://github.com/benpop/lua-int64, in the mean time I'll try a 32bit build to see if it behaves differently.

Another solution might be to maintain an index/list/etc in the CPP and let the Lua scripts refer to the files by index, not pointer.

@qwertychouskie qwertychouskie added the T: Bug Something isn't working label Apr 3, 2019
@qwertychouskie
Copy link
Member Author

qwertychouskie commented Apr 3, 2019

The 32-bit build doesn't fix the crash. :( However, after using long long in the applicable places, the one-tine-per-file crash on writing the config and scores files is gone, despite no changes to Lua itself, so I probably [very hackishly] avoided some sort of undefined behavior.

@qwertychouskie qwertychouskie added the Priority: P2 High priority label Apr 21, 2019
@qwertychouskie qwertychouskie added this to the 0.4 beta milestone Apr 21, 2019
@qwertychouskie
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 High priority T: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants