Skip to content
Permalink
Browse files
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.
  • Loading branch information
peace-maker committed Jun 25, 2020
1 parent a919db5 commit b267567e50784b193bb7c4a74a60dcc5beb2437a
Showing 9 changed files with 104 additions and 80 deletions.
@@ -206,7 +206,7 @@ namespace SourceMM
* @return The newly incremented iface version number.
* @deprecated Use InterfaceSearch() or VInterfaceMatch instead.
*/
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
virtual int FormatIface(char iface[], size_t maxlength) =0;

/**
* @brief Searches for an interface, eliminating the need to loop
@@ -792,13 +792,13 @@ void MetamodSource::GetShVersions(int &shvers, int &shimpl)
shimpl = SH_IMPL_VERSION;
}

int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
int MetamodSource::FormatIface(char iface[], size_t maxlength)
{
int length = (int)strlen(iface);
int i;
size_t length = strlen(iface);
size_t i;
int num = 0;

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

if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
if ( (num && (maxlength <= length)) || (!num && (maxlength <= length + 3)) )
{
return -1;
}
@@ -72,7 +72,7 @@ class MetamodSource : public ISmmAPI
void GetShVersions(int &shvers, int &shimpl);
void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
void *MetaFactory(const char *iface, int *ret, PluginId *id);
int FormatIface(char iface[], unsigned int maxlength);
int FormatIface(char iface[], size_t maxlength);
void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
const char *GetBaseDir();
size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
@@ -184,7 +184,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
const char *plname;
PluginIter i;
char buffer[256];
int len;
size_t len;
int plnum = g_PluginMngr.GetPluginCount();

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

for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
@@ -81,7 +81,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
if (mem.AllocationBase == NULL)
return false;
HMODULE dll = (HMODULE)mem.AllocationBase;
GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
GetModuleFileName(dll, (LPTSTR)buffer, static_cast<DWORD>(maxlength));
#elif defined __linux__ || defined __APPLE__
Dl_info info;
if (!dladdr(pAddr, &info))
@@ -38,10 +38,10 @@

const char *UTIL_GetExtension(const char *file)
{
int len = strlen(file);
int i = 0;
size_t len = strlen(file);
size_t i = 0;

for (i = len - 1; i >= 0; i--)
for (i = len - 1; i + 1 > 0; i--)
{
if (file[i] == '/' || file[i] == '\\')
{
@@ -134,14 +134,14 @@ class String
return 0;
}

int find(const char c, int index = 0) const
size_t find(const char c, size_t index = 0) const
{
int len = static_cast<int>(size());
size_t len = size();
if (len < 1)
return npos;
if (index >= len || index < 0)
if (index >= len)
return npos;
int i = 0;
size_t i = 0;
for (i=index; i<len; i++)
{
if (v[i] == c)
@@ -153,20 +153,20 @@ class String
return npos;
}

int find_last_of(const char c, int index = npos) const
size_t find_last_of(const char c, size_t index = npos) const
{
int len = static_cast<int>(size());
size_t len = size();
if (len < 1)
return npos;
if (index >= len || index < npos)
if (index >= len)
return npos;
int i;
size_t i;
if (index == npos)
i = len - 1;
else
i = index;

for (; i>=0; i--)
for (; i+1>0; i--)
{
if (v[i] == c)
{
@@ -194,8 +194,8 @@ class String
if (!v)
return;

unsigned int i = 0;
unsigned int j = 0;
size_t i = 0;
size_t j = 0;
size_t len = strlen(v);

if (len == 1)
@@ -213,7 +213,7 @@ class String
{
for (i=0; i<len; i++)
{
if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
if (!is_space(v[i]) || (is_space(v[i]) && (i==len-1)))
{
erase(0, i);
break;
@@ -252,11 +252,11 @@ class String
}
}

void erase(unsigned int start, int num = npos)
void erase(size_t start, size_t num = npos)
{
if (!v)
return;
unsigned int i = 0;
size_t i = 0;
size_t len = size();
//check for bounds
if (num == npos || start+num > len-start)
@@ -287,7 +287,7 @@ class String
v[len] = 0;
}

String substr(unsigned int index, int num = npos) const
String substr(size_t index, size_t num = npos) const
{
if (!v)
{
@@ -309,8 +309,8 @@ class String
num = len - index;
}

unsigned int i = 0;
unsigned int nslen = num + 2;
size_t i = 0;
size_t nslen = num + 2;

ns.Grow(nslen);

@@ -324,7 +324,7 @@ class String
{
if (!v)
return;
unsigned int i = 0;
size_t i = 0;
size_t len = strlen(v);
for (i=0; i<len; i++)
{
@@ -346,27 +346,27 @@ class String

}

char operator [] (unsigned int index) const
char operator [] (size_t index) const
{
if (index > size() || !v)
if (index >= size() || !v)
{
return -1;
} else {
return v[index];
}
}

int at(int a) const
int at(size_t a) const
{
if (a < 0 || a >= (int)size() || !v)
if (a >= size() || !v)
return -1;

return v[a];
}

bool at(int at, char c)
bool at(size_t at, char c)
{
if (at < 0 || at >= (int)size() || !v)
if (at >= size() || !v)
return false;

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

private:
void Grow(unsigned int d, bool copy=true)
void Grow(size_t d, bool copy=true)
{
if (d <= a_size)
return;
@@ -385,15 +385,15 @@ class String
if (v)
delete [] v;
else
strcpy(n, "");
strcpy(n, "");
v = n;
a_size = d + 1;
}

char *v;
unsigned int a_size;
size_t a_size;
public:
static const int npos = -1;
static const size_t npos = static_cast<size_t>(-1);
};

}; //NAMESPACE
@@ -2,6 +2,7 @@
#include "sourcehook.h"
#include "sourcehook_test.h"
#include "testevents.h"
#include <ctime>

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

0 comments on commit b267567

Please sign in to comment.