Skip to content

Commit 336e68b

Browse files
Cleanup C4267 warnings (w3dhub#74)
* Fixes to avoid C4267 warnings in Widestring.cpp/h * More C4275 Cleanup * Updated Chunkio * More warning C4267 fixes * More C4267 warnings work * (chore) Cleaned up more warnings including remaining C4267. * Fixes to avoid C4267 warnings in Widestring.cpp/h * More C4275 Cleanup * Updated Chunkio * More warning C4267 fixes * More C4267 warnings work * (chore) Cleaned up more warnings including remaining C4267. * rebase on main * Fixup * Changes requested from PR * Removed the redundant StringClass(unsigned initial_len, bool) overload in Code/wwlib/wwstring.h * Fix indentations * More formating cleanup * More indent cleanup * Attempt to force github repo to switch these files back to CRLF * Remove comment about CRLF * Remove comment about CRLF * Copied files from main and re did changes to see if that fixes whitespace issues in github.
1 parent 9e9e158 commit 336e68b

104 files changed

Lines changed: 934 additions & 601 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Code/BinkMovie/subtitle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void SubTitleClass::Set_Caption(wchar_t* string)
145145

146146
// Make a copy of caption
147147
if (string != NULL) {
148-
unsigned int length = wcslen(string);
148+
size_t length = wcslen(string);
149149
mCaption = new wchar_t[length + 1];
150150
WWASSERT(mCaption != NULL);
151151

Code/Combat/diaglog.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include "wwfile.h"
4040
#include "timemgr.h"
4141

42+
#include <cassert>
43+
#include <limits>
44+
4245
#include <wtypes.h> // for SYSTEMTIME
4346

4447
FileClass * _DiagLogFile = NULL;
@@ -100,8 +103,10 @@ void DiagLogClass::Log_Timed( const char * type, const char * format, ... )
100103

101104
StringClass line;
102105
float time = TimeManager::Get_Total_Seconds();
103-
line.Format( "%s; %1.2f; %s%c%c", type, time, data, 0x0D, 0x0A );
104-
_DiagLogFile->Write( line, ::strlen( line ) );
106+
line.Format("%s; %1.2f; %s%c%c", type, time, data, 0x0D, 0x0A);
107+
const size_t length = ::strlen(line);
108+
assert(length <= static_cast<size_t>(std::numeric_limits<int>::max()));
109+
_DiagLogFile->Write(line, static_cast<int>(length));
105110
}
106111
}
107112

Code/Combat/scriptman.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,20 @@ void ScriptManager::Load_Scripts(const char* dll_filename)
187187

188188
// Copy the dll from the PKG (mix) file into our temporary _scripts directory
189189
static char buffer[16000];
190-
int scripts_size = scripts_dll->Size();
191-
int cur_pos = 0;
190+
size_t scripts_size = scripts_dll->Size();
191+
size_t cur_pos = 0;
192192
while (cur_pos < scripts_size) {
193-
int read_count = WWMath::Min(scripts_size - cur_pos,sizeof(buffer));
194-
scripts_dll->Read(buffer,read_count);
195-
unpacked_scripts.Write(buffer,read_count);
196-
cur_pos += read_count;
193+
size_t remaining = scripts_size - cur_pos;
194+
size_t requested = remaining;
195+
if (requested > sizeof(buffer)) {
196+
requested = sizeof(buffer);
197+
}
198+
int read_count = scripts_dll->Read(buffer, static_cast<int>(requested));
199+
if (read_count <= 0) {
200+
break;
201+
}
202+
unpacked_scripts.Write(buffer, read_count);
203+
cur_pos += static_cast<size_t>(read_count);
197204
}
198205

199206

Code/Combat/soldier.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,19 +1415,22 @@ tm.Rotate_Z( 3.6f );
14151415
FileClass * file = _TheFileFactory->Get_File( name );
14161416
tm.Pre_Rotate_X( 0.3f );
14171417
if ( file && file->Is_Available() ) {
1418-
int size = file->Size();
1418+
size_t size = file->Size();
14191419
tm.Pre_Rotate_Y( 0.4f );
14201420
file->Open();
14211421
tm.Pre_Rotate_Z( 0.5f );
14221422
while ( size > 0 ) {
14231423
unsigned char buffer[ 4096 ];
1424-
int amount = std::min( (int)size, (int)sizeof(buffer) );
1424+
const size_t chunk = std::min<size_t>(size, sizeof(buffer));
14251425
tm.Translate_X( 3.1f );
1426-
amount = file->Read( buffer, amount );
1426+
const int amount = file->Read(buffer, static_cast<int>(chunk));
14271427
tm.Translate_Y( 4.6f );
1428+
if (amount <= 0) {
1429+
break;
1430+
}
14281431
crc = CRC_Memory( buffer, amount, crc );
14291432
tm.Translate_Z( 8.2f );
1430-
size -= amount;
1433+
size -= static_cast<size_t>(amount);
14311434
}
14321435
file->Close();
14331436
} else {
@@ -5308,3 +5311,4 @@ void SoldierGameObj::Update_Locked_Facing( void )
53085311
}
53095312
*/
53105313

5314+

Code/Combat/vehicle.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,12 +2253,12 @@ void VehicleGameObj::Update_Damage_Meshes( void )
22532253
show_damage25 = true;
22542254
}
22552255

2256-
static const char * DAMAGE25_BONE_NAME = "DAMAGE25";
2257-
static const char * DAMAGE50_BONE_NAME = "DAMAGE50";
2258-
static const char * DAMAGE75_BONE_NAME = "DAMAGE75";
2259-
static int DAMAGE25_BONE_NAME_LEN = ::strlen( DAMAGE25_BONE_NAME );
2260-
static int DAMAGE50_BONE_NAME_LEN = ::strlen( DAMAGE50_BONE_NAME );
2261-
static int DAMAGE75_BONE_NAME_LEN = ::strlen( DAMAGE75_BONE_NAME );
2256+
static const char DAMAGE25_BONE_NAME[] = "DAMAGE25";
2257+
static const char DAMAGE50_BONE_NAME[] = "DAMAGE50";
2258+
static const char DAMAGE75_BONE_NAME[] = "DAMAGE75";
2259+
static constexpr size_t DAMAGE25_BONE_NAME_LEN = sizeof( DAMAGE25_BONE_NAME ) - 1;
2260+
static constexpr size_t DAMAGE50_BONE_NAME_LEN = sizeof( DAMAGE50_BONE_NAME ) - 1;
2261+
static constexpr size_t DAMAGE75_BONE_NAME_LEN = sizeof( DAMAGE75_BONE_NAME ) - 1;
22622262

22632263
//
22642264
// Loop over all the bones in the model, showing and hiding any that represent

Code/Combat/viseme.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <string.h>
2020
#include <stdlib.h>
21+
#include <climits>
2122
#include <wwdebug.h>
2223
#include "viseme.h"
2324
#include <ctype.h>
@@ -262,7 +263,7 @@ int VisemeManager::Get_Visemes(const char *word, int *visemelist, int maxvisemes
262263
//
263264
int VisemeManager::Lookup(const char *pchar, const char * /*word*/, int viseme[]) const
264265
{
265-
int length = 0;
266+
size_t length = 0;
266267

267268
char ch = (char)tolower(*pchar);
268269
int index = ch - 'a';
@@ -277,12 +278,13 @@ int VisemeManager::Lookup(const char *pchar, const char * /*word*/, int viseme[]
277278
VisemeTableItem *pI = &gsVisemeTable[pR->StartIndex + pR->Count - 1];
278279
for (int i=0; i<pR->Count; i++,pI--) {
279280
length = strlen(pI->LetterCombination);
280-
if ( strnicmp(pchar, pI->LetterCombination, length) == 0 )
281+
if (strnicmp(pchar, pI->LetterCombination, length) == 0)
281282
{
282283
// found!
283284
viseme[0] = pI->Visemes[0];
284285
viseme[1] = pI->Visemes[1];
285-
return length;
286+
WWASSERT(length <= static_cast<size_t>(INT_MAX));
287+
return static_cast<int>(length);
286288
}
287289
}
288290

Code/Commando/ConsoleMode.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "gamesideservercontrol.h"
5353
#include "specialbuilds.h"
5454
#include "ServerSettings.h"
55+
#include <limits>
5556

5657
/*
5758
** Single instance of console.
@@ -865,20 +866,23 @@ void ConsoleModeClass::Update_Profile(StringClass profile_string)
865866
/*
866867
** Get a checksum of the profile string.
867868
*/
868-
unsigned long crc = CRC::Memory((unsigned char*)profile_string.Peek_Buffer(), profile_string.Get_Length());
869+
const size_t profile_length = profile_string.Get_Length();
870+
WWASSERT(profile_length <= static_cast<size_t>(std::numeric_limits<unsigned long>::max()));
871+
unsigned long crc = CRC::Memory((unsigned char*)profile_string.Peek_Buffer(), static_cast<unsigned long>(profile_length));
869872
if (crc != LastProfileCRC) {
870873

871874

872875
/*
873876
** Create a copy of the string and scan it for '%'.
874877
*/
875-
int len = profile_string.Get_Length();
876-
char *str = (char*) alloca(len * 2);
878+
const size_t len = profile_string.Get_Length();
879+
WWASSERT(len <= static_cast<size_t>(std::numeric_limits<int>::max()));
880+
char *str = (char*) alloca(static_cast<size_t>(len) * 2);
877881
char *src = profile_string.Peek_Buffer();
878882
char *dst = str;
879883
char c;
880884

881-
for (int i=0 ; i<len ; i++) {
885+
for (size_t i=0 ; i<len ; i++) {
882886
c = *src++;
883887
/*
884888
** % = 37. Double up % sign so it prints literally.

Code/Commando/ConsoleMode.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737

3838
#include <win.h>
39+
#include <cstddef>
3940

4041
class WideStringClass;
4142
class StringClass;
@@ -118,7 +119,7 @@ class ConsoleModeClass
118119
** Input parsing variables.
119120
*/
120121
unsigned long LastKeypressTime;
121-
int Pos;
122+
size_t Pos;
122123

123124
/*
124125
** Console title bar contents.
@@ -150,4 +151,4 @@ class ConsoleModeClass
150151
/*
151152
** Single instance of console.
152153
*/
153-
extern ConsoleModeClass ConsoleBox;
154+
extern ConsoleModeClass ConsoleBox;

Code/Commando/DlgWOLLogon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ void DlgWOLLogon::UpdatePersonas(void)
351351
combo->Reset_Content();
352352

353353
const LoginInfoList& personas = LoginInfo::GetList();
354-
const unsigned int count = personas.size();
354+
const size_t count = personas.size();
355355

356-
for (unsigned int index = 0; index < count; ++index)
356+
for (size_t index = 0; index < count; ++index)
357357
{
358358
const WideStringClass& name = personas[index]->GetNickname();
359359
combo->Add_String(name);

Code/Commando/DlgWOLSettings.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ void DlgWOLSettings::InitPersonaCombo(void)
455455
{
456456
// Populate the persona combo box with the list of WWOnline logins.
457457
const LoginInfoList& logins = LoginInfo::GetList();
458-
const unsigned int count = logins.size();
458+
const size_t count = logins.size();
459459

460-
for (unsigned int index = 0; index < count; ++index)
460+
for (size_t index = 0; index < count; ++index)
461461
{
462462
RefPtr<LoginInfo> login = logins[index];
463463
WWASSERT(login.IsValid());
@@ -707,9 +707,9 @@ void DlgWOLSettings::InitServersCombo(const IRCServerList& servers)
707707
int tmpSel = -1;
708708

709709
// walk the list of servers and add them to the combo box
710-
const unsigned int serverCount = servers.size();
710+
const size_t serverCount = servers.size();
711711

712-
for (unsigned int index = 0; index < serverCount; ++index)
712+
for (size_t index = 0; index < serverCount; ++index)
713713
{
714714
const RefPtr<IRCServerData>& server = servers[index];
715715

@@ -733,9 +733,9 @@ void DlgWOLSettings::InitServersCombo(const IRCServerList& servers)
733733
float serverLat = server->GetLattitude();
734734

735735
// Find the ping server with the best time that matches this server's lat/long
736-
const unsigned int pingersCount = pingers.size();
736+
const size_t pingersCount = pingers.size();
737737

738-
for (unsigned int pingindex = 0; pingindex < pingersCount; ++pingindex)
738+
for (size_t pingindex = 0; pingindex < pingersCount; ++pingindex)
739739
{
740740
const RefPtr<PingServerData>& thisPing = pingers[pingindex];
741741
float pingLong = thisPing->GetLongitude();
@@ -952,9 +952,9 @@ void DlgWOLSettings::InitLocaleCombo(void)
952952
std::vector<WideStringClass> localeNames;
953953
mWOLSession->GetLocaleStrings(localeNames);
954954

955-
const unsigned int localeCount = localeNames.size();
955+
const size_t localeCount = localeNames.size();
956956

957-
for (unsigned int index = 0; index < localeCount; ++index)
957+
for (size_t index = 0; index < localeCount; ++index)
958958
{
959959
WideStringClass& locale = localeNames[index];
960960
combo->Add_String(locale);

0 commit comments

Comments
 (0)