Don't use the evil _tcsnccpy/strncpy function.

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6487 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-05-20 17:26:33 +00:00
parent 36deb84820
commit 37233030e1
5 changed files with 20 additions and 30 deletions

View file

@ -40,7 +40,7 @@ int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
return temp;
}
int ConstantsStringList::get(TCHAR *name, int n_chars /*= -1*/)
int ConstantsStringList::get(const TCHAR *name, int n_chars /*= -1*/)
{
int v=SortedStringListND<struct constantstring>::find(name, n_chars);
if (v==-1) return -1;

View file

@ -35,7 +35,7 @@ class ConstantsStringList : public SortedStringListND<struct constantstring>
ConstantsStringList();
int add(const TCHAR *name, int value1, int value2);
int get(TCHAR *name, int n_chars = -1);
int get(const TCHAR *name, int n_chars = -1);
int getnum();
int get_value1(int idx);
int get_value2(int idx);

View file

@ -305,7 +305,7 @@ CEXEBuild::CEXEBuild() :
bg_default_font.lfClipPrecision=CLIP_DEFAULT_PRECIS;
bg_default_font.lfQuality=DEFAULT_QUALITY;
bg_default_font.lfPitchAndFamily=DEFAULT_PITCH;
_tcsnccpy(bg_default_font.lfFaceName,_T("Times New Roman"),LF_FACESIZE);
my_strncpy(bg_default_font.lfFaceName,_T("Times New Roman"),LF_FACESIZE);
memcpy(&bg_font,&bg_default_font,sizeof(LOGFONT));
#endif
@ -609,7 +609,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP
while (pUserVarName > p)
{
if (m_ShellConstants.get((TCHAR*)p, BUGBUG64TRUNCATE(int, pUserVarName-p)) >= 0)
if (m_ShellConstants.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p)) >= 0)
break; // Woops it's a shell constant
// Jim Park: The following line could be a source of bugs for
@ -620,7 +620,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP
// TCHAR varname[NSIS_MAX_STRLEN];
// _tcsncpy(varname, p, pUserVarName-p);
// int idxUserVar = m_UserVarNames.get(varname);
int idxUserVar = m_UserVarNames.get((TCHAR*)p, BUGBUG64TRUNCATE(int, pUserVarName-p));
int idxUserVar = m_UserVarNames.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p));
if (idxUserVar >= 0)
{
// Well, using variables inside string formating doens't mean
@ -709,8 +709,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP
else if ( *p == _T('{') )
cBracket = _T('}');
_tcsnccpy(tbuf,p,63);
tbuf[63]=0;
my_strncpy(tbuf,p,COUNTOF(tbuf));
if ( cBracket != 0 )
{
@ -2427,7 +2426,7 @@ int CEXEBuild::UpdatePEHeader()
void CEXEBuild::set_default_output_filename(const tstring& filename)
{
if (build_output_filename[0] == 0)
_tcsnccpy(build_output_filename,filename.c_str(),1024-1);
my_strncpy(build_output_filename,filename.c_str(),COUNTOF(build_output_filename));
}
int CEXEBuild::check_write_output_errors() const

View file

@ -106,7 +106,7 @@ TCHAR *CEXEBuild::set_file_predefine(const TCHAR *filename)
if(p == filename)
_tcscpy(dir, _T("."));
else
_tcsncpy(dir, filename, p-filename-1);
my_strncpy(dir, filename, p-filename+!0);
#endif
definedlist.add(_T("__FILEDIR__"),dir);
@ -2277,7 +2277,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_ERROR;
#endif//NSIS_CONFIG_SILENT_SUPPORT
case TOK_OUTFILE:
_tcsnccpy(build_output_filename,line.gettoken_str(1),1024-1);
my_strncpy(build_output_filename,line.gettoken_str(1),COUNTOF(build_output_filename));
SCRIPT_MSG(_T("OutFile: \"%") NPRIs _T("\"\n"),build_output_filename);
return PS_OK;
case TOK_INSTDIR:
@ -2451,24 +2451,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
LOGFONT newfont;
newfont.lfHeight=40;
newfont.lfWidth=0;
newfont.lfEscapement=0;
newfont.lfOrientation=0;
newfont.lfEscapement=0, newfont.lfOrientation=0;
newfont.lfWeight=FW_NORMAL;
newfont.lfItalic=FALSE;
newfont.lfUnderline=FALSE;
newfont.lfStrikeOut=FALSE;
newfont.lfItalic=newfont.lfUnderline=newfont.lfStrikeOut=FALSE;
newfont.lfCharSet=DEFAULT_CHARSET;
newfont.lfOutPrecision=OUT_DEFAULT_PRECIS;
newfont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
newfont.lfQuality=DEFAULT_QUALITY;
newfont.lfPitchAndFamily=DEFAULT_PITCH;
_tcsnccpy(newfont.lfFaceName,line.gettoken_str(1),LF_FACESIZE);
my_strncpy(newfont.lfFaceName,line.gettoken_str(1),LF_FACESIZE);
SCRIPT_MSG(_T("BGFont: \"%") NPRIs _T("\""),line.gettoken_str(1));
{
bool height=false;
bool weight=false;
bool height=false, weight=false;
for (int i = 2; i < line.getnumtokens(); i++) {
TCHAR *tok=line.gettoken_str(i);
if (tok[0]==_T('/')) {
@ -2829,7 +2824,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
else
{
const TCHAR*facename = line.gettoken_str(1);
_tcsnccpy(build_font, facename, COUNTOF(build_font));
my_strncpy(build_font, facename, COUNTOF(build_font));
build_font_size = line.gettoken_int(2);
if (!failed) SCRIPT_MSG(_T("SetFont: \"%") NPRIs _T("\" %") NPRIs _T("\n"), facename, line.gettoken_str(2));
@ -3169,8 +3164,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
{
TCHAR* packname = line.gettoken_str(1);
PATH_CONVERT(packname);
_tcsnccpy(build_packname,packname,COUNTOF(build_packname)-1);
_tcsnccpy(build_packcmd,line.gettoken_str(2),COUNTOF(build_packcmd)-1);
my_strncpy(build_packname,packname,COUNTOF(build_packname));
my_strncpy(build_packcmd,line.gettoken_str(2),COUNTOF(build_packcmd));
SCRIPT_MSG(_T("!packhdr: filename=\"%") NPRIs _T("\", command=\"%") NPRIs _T("\"\n"),
build_packname, build_packcmd);
}
@ -4146,15 +4141,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return add_entry(&ent);
case TOK_CREATEDIR:
{
TCHAR out_path[1024];
TCHAR *p=line.gettoken_str(1);
TCHAR out_path[NSIS_MAX_STRLEN], *p=line.gettoken_str(1);
if (*p == _T('-')) out_path[0]=0;
else
{
if (p[0] == _T('\\') && p[1] != _T('\\')) p++;
_tcsnccpy(out_path,p,1024-1);
if (*CharPrev(out_path,out_path+_tcslen(out_path))==_T('\\'))
*CharPrev(out_path,out_path+_tcslen(out_path))=0; // remove trailing slash
my_strncpy(out_path,p,COUNTOF(out_path));
p=CharPrev(out_path,out_path+_tcslen(out_path));
if (_T('\\') == *p || _T('/') == *p) *p=0; // remove trailing slash
}
if (!*out_path) PRINTHELP()
SCRIPT_MSG(_T("CreateDirectory: \"%") NPRIs _T("\"\n"),out_path);

View file

@ -75,8 +75,6 @@ typedef wchar_t TCHAR, _TUCHAR;
#define _tcscpy wcscpy
#define _tcsdup _wcsdup
#define _tcslen wcslen
#define _tcsnccpy wcsncpy
#define _tcsncpy wcsncpy
#define _tcsrchr wcsrchr
#define _tcsstr wcsstr
#define _tcstok wcstok
@ -176,7 +174,6 @@ typedef unsigned char _TUCHAR;
#define _tcscpy strcpy
#define _tcsdup _strdup
#define _tcslen strlen
#define _tcsnccpy strncpy
#define _tcsrchr strrchr
#define _tcsstr strstr
#define _tcstok strtok