InterfaceSearch no longer uses new[]
authorDavid Anderson <dvander@alliedmods.net>
Tue Aug 15 21:34:36 2006 +0000 (2006-08-15)
changeset 2536d9216d67678
parent 252 080f0438e0cb
child 254 6b3875163736
InterfaceSearch no longer uses new[]
sourcemm/CSmmAPI.cpp
     1.1 --- a/sourcemm/CSmmAPI.cpp	Tue Aug 15 20:28:18 2006 +0000
     1.2 +++ b/sourcemm/CSmmAPI.cpp	Tue Aug 15 21:34:36 2006 +0000
     1.3 @@ -334,14 +334,23 @@
     1.4  
     1.5  void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
     1.6  {
     1.7 +	char _if[256];	/* assume no interface goes beyond this */
     1.8  	size_t len = strlen(iface);
     1.9  	int num = 0;
    1.10  	void *pf = NULL;
    1.11 -	char *_if = new char[len + 2];
    1.12  
    1.13  	if (max > 999)
    1.14  		max = 999;
    1.15  
    1.16 +	if (len + 4 > sizeof(_if))
    1.17 +	{
    1.18 +		if (ret)
    1.19 +		{
    1.20 +			*ret = IFACE_FAILED;
    1.21 +		}
    1.22 +		return NULL;
    1.23 +	}
    1.24 +
    1.25  	strcpy(_if, iface);
    1.26  
    1.27  	do
    1.28 @@ -352,8 +361,6 @@
    1.29  			break;
    1.30  	} while (( num = FormatIface(_if, len+1) ));
    1.31  
    1.32 -	delete[] _if;
    1.33 -
    1.34  	return pf;
    1.35  }
    1.36