diff --git a/common/lua_manager.cpp b/common/lua_manager.cpp index e31deb9f6..7716178ae 100644 --- a/common/lua_manager.cpp +++ b/common/lua_manager.cpp @@ -32,21 +32,20 @@ int check_file( const char* file_name, char* err_str ) strcpy( err_str, "" ); FILE *f = fopen( file_name, "r"); - if ( 0 == f ) + if ( !f ) { G_LOG->error( err_str, "File \"%s\" not found!", file_name ); return -1; } int version = 0; - char str[ 100 ] = ""; - if ( char* res = fgets(str, sizeof(str), f); res != 0 ) + if ( char str[ 100 ] = ""; fgets( str, sizeof( str ), f ) ) { int err = sscanf( str, "--version = %d", &version ); } fclose( f ); - f = 0; + f = nullptr; if ( G_DEBUG ) { diff --git a/test/lua_manager_tests.cpp b/test/lua_manager_tests.cpp index 690afae38..987c973d1 100644 --- a/test/lua_manager_tests.cpp +++ b/test/lua_manager_tests.cpp @@ -753,3 +753,18 @@ TEST( lua_manager, error_trace ) EXPECT_NE( 0, G_LUA_MANAGER->void_exec_lua_method( "t", "no_exist3", "error_trace" ) ); G_LUA_MANAGER->free_Lua(); } + +TEST( lua_manager, check_file ) + { + auto FILE_VERSION = 10; + char err_str[ 500 ] = {}; + const char* FILE_NAME = "test.lua"; + if ( FILE* f = std::fopen( FILE_NAME, "w+" ) ) + { + std::fprintf( f, "--version = %d\n", FILE_VERSION ); + std::fclose( f ); + } + + auto res = check_file( FILE_NAME, err_str ); + EXPECT_EQ( res, FILE_VERSION ); + }