Browse Source

platform: win32: replace Q_sprintf calls by Q_snprintf

pull/2/head
Alibek Omarov 2 years ago
parent
commit
a292d2fd53
  1. 14
      engine/platform/win32/lib_custom_win.c
  2. 40
      engine/platform/win32/lib_win.c

14
engine/platform/win32/lib_custom_win.c

@ -373,21 +373,21 @@ void *MemoryLoadLibrary( const char *name ) @@ -373,21 +373,21 @@ void *MemoryLoadLibrary( const char *name )
if( !data )
{
Q_sprintf( errorstring, "couldn't load %s", name );
Q_snprintf( errorstring, sizeof( errorstring ), "couldn't load %s", name );
goto library_error;
}
dos_header = (PIMAGE_DOS_HEADER)data;
if( dos_header->e_magic != IMAGE_DOS_SIGNATURE )
{
Q_sprintf( errorstring, "%s it's not a valid executable file", name );
Q_snprintf( errorstring, sizeof( errorstring ), "%s it's not a valid executable file", name );
goto library_error;
}
old_header = (PIMAGE_NT_HEADERS)&((const byte *)(data))[dos_header->e_lfanew];
if( old_header->Signature != IMAGE_NT_SIGNATURE )
{
Q_sprintf( errorstring, "%s missing PE header", name );
Q_snprintf( errorstring, sizeof( errorstring ), "%s missing PE header", name );
goto library_error;
}
@ -402,7 +402,7 @@ void *MemoryLoadLibrary( const char *name ) @@ -402,7 +402,7 @@ void *MemoryLoadLibrary( const char *name )
if( code == NULL )
{
Q_sprintf( errorstring, "%s can't reserve memory", name );
Q_snprintf( errorstring, sizeof( errorstring ), "%s can't reserve memory", name );
goto library_error;
}
@ -436,7 +436,7 @@ void *MemoryLoadLibrary( const char *name ) @@ -436,7 +436,7 @@ void *MemoryLoadLibrary( const char *name )
// load required dlls and adjust function table of imports
if( !BuildImportTable( result ))
{
Q_sprintf( errorstring, "%s failed to build import table", name );
Q_snprintf( errorstring, sizeof( errorstring ), "%s failed to build import table", name );
goto library_error;
}
@ -450,7 +450,7 @@ void *MemoryLoadLibrary( const char *name ) @@ -450,7 +450,7 @@ void *MemoryLoadLibrary( const char *name )
DllEntry = (DllEntryProc)CALCULATE_ADDRESS( code, result->headers->OptionalHeader.AddressOfEntryPoint );
if( DllEntry == 0 )
{
Q_sprintf( errorstring, "%s has no entry point", name );
Q_snprintf( errorstring, sizeof( errorstring ), "%s has no entry point", name );
goto library_error;
}
@ -458,7 +458,7 @@ void *MemoryLoadLibrary( const char *name ) @@ -458,7 +458,7 @@ void *MemoryLoadLibrary( const char *name )
successfull = (*DllEntry)((HINSTANCE)code, DLL_PROCESS_ATTACH, 0 );
if( !successfull )
{
Q_sprintf( errorstring, "can't attach library %s", name );
Q_snprintf( errorstring, sizeof( errorstring ), "can't attach library %s", name );
goto library_error;
}
result->initialized = 1;

40
engine/platform/win32/lib_win.c

@ -101,55 +101,55 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -101,55 +101,55 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
f = FS_Open( hInst->shortPath, "rb", false );
if( !f )
{
Q_sprintf( errorstring, "couldn't load %s", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "couldn't load %s", hInst->shortPath );
goto table_error;
}
if( FS_Read( f, &dos_header, sizeof( dos_header )) != sizeof( dos_header ))
{
Q_sprintf( errorstring, "%s has corrupted EXE header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s has corrupted EXE header", hInst->shortPath );
goto table_error;
}
if( dos_header.e_magic != IMAGE_DOS_SIGNATURE )
{
Q_sprintf( errorstring, "%s does not have a valid dll signature", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid dll signature", hInst->shortPath );
goto table_error;
}
if( FS_Seek( f, dos_header.e_lfanew, SEEK_SET ) == -1 )
{
Q_sprintf( errorstring, "%s error seeking for new exe header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error seeking for new exe header", hInst->shortPath );
goto table_error;
}
if( FS_Read( f, &nt_signature, sizeof( nt_signature )) != sizeof( nt_signature ))
{
Q_sprintf( errorstring, "%s has corrupted NT header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s has corrupted NT header", hInst->shortPath );
goto table_error;
}
if( nt_signature != IMAGE_NT_SIGNATURE )
{
Q_sprintf( errorstring, "%s does not have a valid NT signature", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid NT signature", hInst->shortPath );
goto table_error;
}
if( FS_Read( f, &pe_header, sizeof( pe_header )) != sizeof( pe_header ))
{
Q_sprintf( errorstring, "%s does not have a valid PE header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid PE header", hInst->shortPath );
goto table_error;
}
if( !pe_header.SizeOfOptionalHeader )
{
Q_sprintf( errorstring, "%s does not have an optional header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have an optional header", hInst->shortPath );
goto table_error;
}
if( FS_Read( f, &optional_header, sizeof( optional_header )) != sizeof( optional_header ))
{
Q_sprintf( errorstring, "%s optional header probably corrupted", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s optional header probably corrupted", hInst->shortPath );
goto table_error;
}
@ -159,7 +159,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -159,7 +159,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
{
if( FS_Read( f, &section_header, sizeof( section_header )) != sizeof( section_header ))
{
Q_sprintf( errorstring, "%s error during reading section header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error during reading section header", hInst->shortPath );
goto table_error;
}
@ -180,13 +180,13 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -180,13 +180,13 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Seek( f, exports_offset, SEEK_SET ) == -1 )
{
Q_sprintf( errorstring, "%s does not have a valid exports section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid exports section", hInst->shortPath );
goto table_error;
}
if( FS_Read( f, &export_directory, sizeof( export_directory )) != sizeof( export_directory ))
{
Q_sprintf( errorstring, "%s does not have a valid optional header", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid optional header", hInst->shortPath );
goto table_error;
}
@ -194,7 +194,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -194,7 +194,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( hInst->num_ordinals > MAX_LIBRARY_EXPORTS )
{
Q_sprintf( errorstring, "%s too many exports %i", hInst->shortPath, hInst->num_ordinals );
Q_snprintf( errorstring, sizeof( errorstring ), "%s too many exports %i", hInst->shortPath, hInst->num_ordinals );
hInst->num_ordinals = 0;
goto table_error;
}
@ -203,7 +203,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -203,7 +203,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Seek( f, ordinal_offset, SEEK_SET ) == -1 )
{
Q_sprintf( errorstring, "%s does not have a valid ordinals section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid ordinals section", hInst->shortPath );
goto table_error;
}
@ -211,7 +211,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -211,7 +211,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Read( f, hInst->ordinals, hInst->num_ordinals * sizeof( word )) != (hInst->num_ordinals * sizeof( word )))
{
Q_sprintf( errorstring, "%s error during reading ordinals table", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error during reading ordinals table", hInst->shortPath );
goto table_error;
}
@ -219,7 +219,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -219,7 +219,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Seek( f, function_offset, SEEK_SET ) == -1 )
{
Q_sprintf( errorstring, "%s does not have a valid export address section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s does not have a valid export address section", hInst->shortPath );
goto table_error;
}
@ -227,7 +227,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -227,7 +227,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Read( f, hInst->funcs, hInst->num_ordinals * sizeof( dword )) != (hInst->num_ordinals * sizeof( dword )))
{
Q_sprintf( errorstring, "%s error during reading export address section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error during reading export address section", hInst->shortPath );
goto table_error;
}
@ -235,7 +235,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -235,7 +235,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Seek( f, name_offset, SEEK_SET ) == -1 )
{
Q_sprintf( errorstring, "%s file does not have a valid names section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s file does not have a valid names section", hInst->shortPath );
goto table_error;
}
@ -243,7 +243,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -243,7 +243,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( FS_Read( f, p_Names, hInst->num_ordinals * sizeof( dword )) != (hInst->num_ordinals * sizeof( dword )))
{
Q_sprintf( errorstring, "%s error during reading names table", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error during reading names table", hInst->shortPath );
goto table_error;
}
@ -264,7 +264,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst ) @@ -264,7 +264,7 @@ qboolean LibraryLoadSymbols( dll_user_t *hInst )
if( i != hInst->num_ordinals )
{
Q_sprintf( errorstring, "%s error during loading names section", hInst->shortPath );
Q_snprintf( errorstring, sizeof( errorstring ), "%s error during loading names section", hInst->shortPath );
goto table_error;
}
FS_Close( f );

Loading…
Cancel
Save