Merge branch 'rm-strncopy'

This commit is contained in:
David Anderson 2015-08-30 18:38:31 -07:00
commit c261bb0b2e
10 changed files with 28 additions and 50 deletions

View File

@ -718,7 +718,7 @@ ConfigResult Translator::OnSourceModConfigChanged(const char *key,
m_ServerLang = index; m_ServerLang = index;
} else { } else {
smcore.strncopy(m_InitialLang, value, sizeof(m_InitialLang)); strncopy(m_InitialLang, value, sizeof(m_InitialLang));
} }
return ConfigResult_Accept; return ConfigResult_Accept;
@ -840,7 +840,7 @@ void Translator::RebuildLanguageDatabase()
{ {
logger->LogError("Server language was set to bad language \"%s\" -- reverting to English", m_InitialLang); logger->LogError("Server language was set to bad language \"%s\" -- reverting to English", m_InitialLang);
smcore.strncopy(m_InitialLang, "en", sizeof(m_InitialLang)); strncopy(m_InitialLang, "en", sizeof(m_InitialLang));
m_ServerLang = SOURCEMOD_LANGUAGE_ENGLISH; m_ServerLang = SOURCEMOD_LANGUAGE_ENGLISH;
} }

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 31) #define SM_LOGIC_MAGIC (0x0F47C0DE - 32)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer
@ -293,7 +293,6 @@ struct sm_core_t
ISourcePawnEngine2 **spe2; ISourcePawnEngine2 **spe2;
/* Functions */ /* Functions */
ConVar * (*FindConVar)(const char*); ConVar * (*FindConVar)(const char*);
unsigned int (*strncopy)(char*, const char*, size_t);
char * (*TrimWhitespace)(char *, size_t &); char * (*TrimWhitespace)(char *, size_t &);
void (*LogToGame)(const char *message); void (*LogToGame)(const char *message);
void (*ConPrint)(const char *message); void (*ConPrint)(const char *message);

View File

@ -1,5 +1,5 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@ -32,6 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "CellArray.h"
#include "stringutil.h"
HandleType_t htCellArray; HandleType_t htCellArray;
@ -181,7 +182,7 @@ static cell_t PushArrayString(IPluginContext *pContext, const cell_t *params)
char *str; char *str;
pContext->LocalToString(params[2], &str); pContext->LocalToString(params[2], &str);
smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t));
return (cell_t)(array->size() - 1); return (cell_t)(array->size() - 1);
} }
@ -378,7 +379,7 @@ static cell_t SetArrayString(IPluginContext *pContext, const cell_t *params)
char *str; char *str;
pContext->LocalToString(params[3], &str); pContext->LocalToString(params[3], &str);
return smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); return strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t));
} }
static cell_t SetArrayArray(IPluginContext *pContext, const cell_t *params) static cell_t SetArrayArray(IPluginContext *pContext, const cell_t *params)

View File

@ -33,6 +33,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "CellArray.h"
#include "handle_helpers.h" #include "handle_helpers.h"
#include "stringutil.h"
HandleType_t htCellStack; HandleType_t htCellStack;
@ -125,7 +126,7 @@ static cell_t PushStackString(IPluginContext *pContext, const cell_t *params)
char *str; char *str;
pContext->LocalToString(params[2], &str); pContext->LocalToString(params[2], &str);
smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t));
return 1; return 1;
} }

View File

@ -337,7 +337,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
{ {
/* Get the IP address and strip the port */ /* Get the IP address and strip the port */
char ip[24], *ptr; char ip[24], *ptr;
smcore.strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip)); strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
if ((ptr = strchr(ip, ':')) != NULL) if ((ptr = strchr(ip, ':')) != NULL)
{ {
*ptr = '\0'; *ptr = '\0';

View File

@ -110,9 +110,9 @@ public:
pMapList->bIsCompat = true; pMapList->bIsCompat = true;
pMapList->bIsPath = true; pMapList->bIsPath = true;
pMapList->last_modified_time = 0; pMapList->last_modified_time = 0;
smcore.strncopy(pMapList->name, name, sizeof(pMapList->name)); strncopy(pMapList->name, name, sizeof(pMapList->name));
pMapList->pArray = NULL; pMapList->pArray = NULL;
smcore.strncopy(pMapList->path, file, sizeof(pMapList->path)); strncopy(pMapList->path, file, sizeof(pMapList->path));
pMapList->serial = 0; pMapList->serial = 0;
m_ListLookup.insert(name, pMapList); m_ListLookup.insert(name, pMapList);
m_MapLists.push_back(pMapList); m_MapLists.push_back(pMapList);
@ -123,13 +123,13 @@ public:
if (!pMapList->bIsCompat) if (!pMapList->bIsCompat)
return; return;
smcore.strncopy(path, file, sizeof(path)); strncopy(path, file, sizeof(path));
/* If the path matches, don't reset the serial/time */ /* If the path matches, don't reset the serial/time */
if (strcmp(path, pMapList->path) == 0) if (strcmp(path, pMapList->path) == 0)
return; return;
smcore.strncopy(pMapList->path, path, sizeof(pMapList->path)); strncopy(pMapList->path, path, sizeof(pMapList->path));
pMapList->bIsPath = true; pMapList->bIsPath = true;
pMapList->last_modified_time = 0; pMapList->last_modified_time = 0;
pMapList->serial = 0; pMapList->serial = 0;
@ -168,7 +168,7 @@ public:
maplist_info_t *pDefList = new maplist_info_t; maplist_info_t *pDefList = new maplist_info_t;
pDefList->bIsPath = true; pDefList->bIsPath = true;
smcore.strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name)); strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name));
GetMapCycleFilePath(pDefList->path, sizeof(pDefList->path)); GetMapCycleFilePath(pDefList->path, sizeof(pDefList->path));
@ -246,7 +246,7 @@ public:
m_pCurMapList = new maplist_info_t; m_pCurMapList = new maplist_info_t;
memset(m_pCurMapList, 0, sizeof(maplist_info_t)); memset(m_pCurMapList, 0, sizeof(maplist_info_t));
smcore.strncopy(m_pCurMapList->name, name, sizeof(m_pCurMapList->name)); strncopy(m_pCurMapList->name, name, sizeof(m_pCurMapList->name));
m_CurState = MPS_MAPLIST; m_CurState = MPS_MAPLIST;
} }
@ -266,12 +266,12 @@ public:
if (strcmp(key, "file") == 0) if (strcmp(key, "file") == 0)
{ {
smcore.strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path)); strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path));
m_pCurMapList->bIsPath = true; m_pCurMapList->bIsPath = true;
} }
else if (strcmp(key, "target") == 0) else if (strcmp(key, "target") == 0)
{ {
smcore.strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path)); strncopy(m_pCurMapList->path, value, sizeof(m_pCurMapList->path));
m_pCurMapList->bIsPath = false; m_pCurMapList->bIsPath = false;
} }
@ -383,7 +383,7 @@ public:
continue; continue;
} }
smcore.strncopy((char *)blk, buffer, 255); strncopy((char *)blk, buffer, 255);
fileName = smcore.filesystem->FindNext(findHandle); fileName = smcore.filesystem->FindNext(findHandle);
} }
@ -442,7 +442,7 @@ public:
{ {
blk_dst = pUseArray->push(); blk_dst = pUseArray->push();
blk_src = pNewArray->at(i); blk_src = pNewArray->at(i);
smcore.strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t));
} }
/* Free resources if necessary. */ /* Free resources if necessary. */
@ -480,7 +480,7 @@ private:
if (strcmp(path, pMapList->path) != 0) if (strcmp(path, pMapList->path) != 0)
{ {
smcore.strncopy(pMapList->path, path, sizeof(pMapList->path)); strncopy(pMapList->path, path, sizeof(pMapList->path));
pMapList->last_modified_time = 0; pMapList->last_modified_time = 0;
} }
} }
@ -535,7 +535,7 @@ private:
if ((blk = pMapList->pArray->push()) != NULL) if ((blk = pMapList->pArray->push()) != NULL)
{ {
smcore.strncopy((char *)blk, ptr, 255); strncopy((char *)blk, ptr, 255);
} }
} }

View File

@ -40,6 +40,7 @@
#include "GameConfigs.h" #include "GameConfigs.h"
#include "CellArray.h" #include "CellArray.h"
#include "AutoHandleRooter.h" #include "AutoHandleRooter.h"
#include "stringutil.h"
using namespace SourceHook; using namespace SourceHook;
using namespace SourceMod; using namespace SourceMod;
@ -163,7 +164,7 @@ public: //ICommandTargetProcessor
? COMMAND_TARGET_VALID ? COMMAND_TARGET_VALID
: COMMAND_TARGET_EMPTY_FILTER; : COMMAND_TARGET_EMPTY_FILTER;
if (info->num_targets) { if (info->num_targets) {
smcore.strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength); strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength);
info->target_name_style = smtf->phraseIsML info->target_name_style = smtf->phraseIsML
? COMMAND_TARGETNAME_ML ? COMMAND_TARGETNAME_ML
: COMMAND_TARGETNAME_RAW; : COMMAND_TARGETNAME_RAW;

View File

@ -1,5 +1,5 @@
/** /**
* vim: set ts=4 sw=4 tw=99 et : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
@ -34,6 +34,7 @@
#include <ctype.h> #include <ctype.h>
#include <sm_platform.h> #include <sm_platform.h>
#include "stringutil.h" #include "stringutil.h"
#include <am-string.h>
// We're in logic so we don't have this from the SDK. // We're in logic so we don't have this from the SDK.
#ifndef MIN #ifndef MIN
@ -73,19 +74,7 @@ const char *stristr(const char *str, const char *substr)
unsigned int strncopy(char *dest, const char *src, size_t count) unsigned int strncopy(char *dest, const char *src, size_t count)
{ {
if (!count) return ke::SafeStrcpy(dest, count, src);
{
return 0;
}
char *start = dest;
while ((*src) && (--count))
{
*dest++ = *src++;
}
*dest = '\0';
return (dest - start);
} }
unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive) unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive)

View File

@ -583,7 +583,6 @@ static sm_core_t core_bridge =
&g_pSourcePawn2, &g_pSourcePawn2,
/* Functions */ /* Functions */
find_convar, find_convar,
strncopy,
UTIL_TrimWhitespace, UTIL_TrimWhitespace,
log_to_game, log_to_game,
conprint, conprint,

View File

@ -1280,19 +1280,7 @@ done:
unsigned int strncopy(char *dest, const char *src, size_t count) unsigned int strncopy(char *dest, const char *src, size_t count)
{ {
if (!count) return ke::SafeStrcpy(dest, count, src);
{
return 0;
}
char *start = dest;
while ((*src) && (--count))
{
*dest++ = *src++;
}
*dest = '\0';
return (dest - start);
} }
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...) size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)