Skip to content

Commit b267567

Browse files
authored
Fix detection of Blade Symphony on Windows x64 (#67)
* Fix detection of Blade Symphony on Windows x64 Port finding the module base address on x64 builds from SourceMod. Fix a bunch of truncation warnings on x64 while at it too. * Fix mm_TrimComments stripping last char before comment ```c char test[] = "hi this is a a test!// comment"; mm_TrimComments(test); puts(test); // prints "hi this is a test" without the ! ``` * Fix unsigned comparison warnings * Fix truncation warnings in SourceHook::String * Fix unsigned comparison warnings clang does have some nice analysis.
1 parent a919db5 commit b267567

File tree

9 files changed

+104
-80
lines changed

9 files changed

+104
-80
lines changed

Diff for: core/ISmmAPI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ namespace SourceMM
206206
* @return The newly incremented iface version number.
207207
* @deprecated Use InterfaceSearch() or VInterfaceMatch instead.
208208
*/
209-
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
209+
virtual int FormatIface(char iface[], size_t maxlength) =0;
210210

211211
/**
212212
* @brief Searches for an interface, eliminating the need to loop

Diff for: core/metamod.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,13 @@ void MetamodSource::GetShVersions(int &shvers, int &shimpl)
792792
shimpl = SH_IMPL_VERSION;
793793
}
794794

795-
int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
795+
int MetamodSource::FormatIface(char iface[], size_t maxlength)
796796
{
797-
int length = (int)strlen(iface);
798-
int i;
797+
size_t length = strlen(iface);
798+
size_t i;
799799
int num = 0;
800800

801-
for (i = length - 1; i >= 0; i--)
801+
for (i = length - 1; i + 1 > 0; i--)
802802
{
803803
if (!isdigit(iface[i]))
804804
{
@@ -810,7 +810,7 @@ int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
810810
}
811811
}
812812

813-
if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
813+
if ( (num && (maxlength <= length)) || (!num && (maxlength <= length + 3)) )
814814
{
815815
return -1;
816816
}

Diff for: core/metamod.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MetamodSource : public ISmmAPI
7272
void GetShVersions(int &shvers, int &shimpl);
7373
void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
7474
void *MetaFactory(const char *iface, int *ret, PluginId *id);
75-
int FormatIface(char iface[], unsigned int maxlength);
75+
int FormatIface(char iface[], size_t maxlength);
7676
void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
7777
const char *GetBaseDir();
7878
size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);

Diff for: core/metamod_console.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
184184
const char *plname;
185185
PluginIter i;
186186
char buffer[256];
187-
int len;
187+
size_t len;
188188
int plnum = g_PluginMngr.GetPluginCount();
189189

190190
if (!plnum)
@@ -688,7 +688,7 @@ bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
688688
const char *plname;
689689
PluginIter i;
690690
char buffer[256];
691-
int len = 0;
691+
size_t len = 0;
692692
int plnum = 0;
693693

694694
for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)

Diff for: core/metamod_oslink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
8181
if (mem.AllocationBase == NULL)
8282
return false;
8383
HMODULE dll = (HMODULE)mem.AllocationBase;
84-
GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
84+
GetModuleFileName(dll, (LPTSTR)buffer, static_cast<DWORD>(maxlength));
8585
#elif defined __linux__ || defined __APPLE__
8686
Dl_info info;
8787
if (!dladdr(pAddr, &info))

Diff for: core/metamod_util.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838

3939
const char *UTIL_GetExtension(const char *file)
4040
{
41-
int len = strlen(file);
42-
int i = 0;
41+
size_t len = strlen(file);
42+
size_t i = 0;
4343

44-
for (i = len - 1; i >= 0; i--)
44+
for (i = len - 1; i + 1 > 0; i--)
4545
{
4646
if (file[i] == '/' || file[i] == '\\')
4747
{

Diff for: core/sourcehook/sh_string.h

+28-28
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ class String
134134
return 0;
135135
}
136136

137-
int find(const char c, int index = 0) const
137+
size_t find(const char c, size_t index = 0) const
138138
{
139-
int len = static_cast<int>(size());
139+
size_t len = size();
140140
if (len < 1)
141141
return npos;
142-
if (index >= len || index < 0)
142+
if (index >= len)
143143
return npos;
144-
int i = 0;
144+
size_t i = 0;
145145
for (i=index; i<len; i++)
146146
{
147147
if (v[i] == c)
@@ -153,20 +153,20 @@ class String
153153
return npos;
154154
}
155155

156-
int find_last_of(const char c, int index = npos) const
156+
size_t find_last_of(const char c, size_t index = npos) const
157157
{
158-
int len = static_cast<int>(size());
158+
size_t len = size();
159159
if (len < 1)
160160
return npos;
161-
if (index >= len || index < npos)
161+
if (index >= len)
162162
return npos;
163-
int i;
163+
size_t i;
164164
if (index == npos)
165165
i = len - 1;
166166
else
167167
i = index;
168168

169-
for (; i>=0; i--)
169+
for (; i+1>0; i--)
170170
{
171171
if (v[i] == c)
172172
{
@@ -194,8 +194,8 @@ class String
194194
if (!v)
195195
return;
196196

197-
unsigned int i = 0;
198-
unsigned int j = 0;
197+
size_t i = 0;
198+
size_t j = 0;
199199
size_t len = strlen(v);
200200

201201
if (len == 1)
@@ -213,7 +213,7 @@ class String
213213
{
214214
for (i=0; i<len; i++)
215215
{
216-
if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
216+
if (!is_space(v[i]) || (is_space(v[i]) && (i==len-1)))
217217
{
218218
erase(0, i);
219219
break;
@@ -252,11 +252,11 @@ class String
252252
}
253253
}
254254

255-
void erase(unsigned int start, int num = npos)
255+
void erase(size_t start, size_t num = npos)
256256
{
257257
if (!v)
258258
return;
259-
unsigned int i = 0;
259+
size_t i = 0;
260260
size_t len = size();
261261
//check for bounds
262262
if (num == npos || start+num > len-start)
@@ -287,7 +287,7 @@ class String
287287
v[len] = 0;
288288
}
289289

290-
String substr(unsigned int index, int num = npos) const
290+
String substr(size_t index, size_t num = npos) const
291291
{
292292
if (!v)
293293
{
@@ -309,8 +309,8 @@ class String
309309
num = len - index;
310310
}
311311

312-
unsigned int i = 0;
313-
unsigned int nslen = num + 2;
312+
size_t i = 0;
313+
size_t nslen = num + 2;
314314

315315
ns.Grow(nslen);
316316

@@ -324,7 +324,7 @@ class String
324324
{
325325
if (!v)
326326
return;
327-
unsigned int i = 0;
327+
size_t i = 0;
328328
size_t len = strlen(v);
329329
for (i=0; i<len; i++)
330330
{
@@ -346,27 +346,27 @@ class String
346346

347347
}
348348

349-
char operator [] (unsigned int index) const
349+
char operator [] (size_t index) const
350350
{
351-
if (index > size() || !v)
351+
if (index >= size() || !v)
352352
{
353353
return -1;
354354
} else {
355355
return v[index];
356356
}
357357
}
358358

359-
int at(int a) const
359+
int at(size_t a) const
360360
{
361-
if (a < 0 || a >= (int)size() || !v)
361+
if (a >= size() || !v)
362362
return -1;
363363

364364
return v[a];
365365
}
366366

367-
bool at(int at, char c)
367+
bool at(size_t at, char c)
368368
{
369-
if (at < 0 || at >= (int)size() || !v)
369+
if (at >= size() || !v)
370370
return false;
371371

372372
v[at] = c;
@@ -375,7 +375,7 @@ class String
375375
}
376376

377377
private:
378-
void Grow(unsigned int d, bool copy=true)
378+
void Grow(size_t d, bool copy=true)
379379
{
380380
if (d <= a_size)
381381
return;
@@ -385,15 +385,15 @@ class String
385385
if (v)
386386
delete [] v;
387387
else
388-
strcpy(n, "");
388+
strcpy(n, "");
389389
v = n;
390390
a_size = d + 1;
391391
}
392392

393393
char *v;
394-
unsigned int a_size;
394+
size_t a_size;
395395
public:
396-
static const int npos = -1;
396+
static const size_t npos = static_cast<size_t>(-1);
397397
};
398398

399399
}; //NAMESPACE

Diff for: core/sourcehook/test/testvphooks.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "sourcehook.h"
33
#include "sourcehook_test.h"
44
#include "testevents.h"
5+
#include <ctime>
56

67
// TEST VP HOOKS
78
// Test vfnptr-wide hooks

0 commit comments

Comments
 (0)