Fixed POSIX !searchparse bug (patch #251) and hopefully better compatibility with 2.46

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6485 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-05-19 19:23:06 +00:00
parent 881fa61896
commit 0bcb8f40ed
7 changed files with 31 additions and 49 deletions

View file

@ -6,6 +6,10 @@ Released on ?, 2014
\S1{v3.0b1-cl} Changelog
\S2{} Minor Changes
\b Fixed POSIX !searchparse bug (\W{http://sf.net/p/nsis/patches/251}{patch #251})
\S2{} Translations
\b Added Armenian (Hrant Ohanyan)

View file

@ -848,7 +848,7 @@ static void CreatePlatformStrfmt(const TCHAR *templ, TCHAR *out) {
if (*out == L'%' && *templ == L's')
{
out++, templ++;
unsigned int cch = my_strncpy(out, NPRIs, -1);
size_t cch = my_strncpy(out, NPRIs, -1);
out += --cch; // --cch because for loop does out++
}
}

View file

@ -3470,13 +3470,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int i;
for (i=0;i<list->getnum(); i ++)
{
TCHAR *def=list->getname(i);
TCHAR *val=list->getvalue(i);
if (def && val)
{
if (definedlist.find(def)) definedlist.del(def);
definedlist.add(def,val);
}
TCHAR *def=list->getname(i), *val=list->getvalue(i);
if (def && val) definedlist.set(def,val);
}
}
delete list;
@ -6791,6 +6786,7 @@ int CEXEBuild::do_add_file_create_dir(const tstring& local_dir, const tstring& d
DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser&line, int parmOffs, bool ignCase, bool noErrors, UINT*failParam)
{
const bool allowEmptyFirstTok = true;
if (failParam) *failParam = 0;
DefineList *ret = NULL;
const TCHAR *defout = 0, *src_start = 0, *tok;
@ -6799,7 +6795,7 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser&
{
tok = line.gettoken_str(parmOffs++);
const bool lasttoken = parmOffs > line.getnumtokens();
if (!tok || !*tok)
if (!*tok)
tok = 0, maxlen = -1; // No more tokens to search for, save the rest of the string
else
{
@ -6813,17 +6809,10 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser&
if (maxlen < 0)
ret->add(defout,src_start);
else
{
TCHAR *p = _tcsdup(src_start);
if (p)
{
p[maxlen] = 0;
ret->add(defout,p);
free(p);
}
}
ret->addn(defout,maxlen,src_start);
}
if (!*source_string || (!tok && !lasttoken)) // We did not find the requested token!
if (!tok && lasttoken) break;
if (!*source_string || (allowEmptyFirstTok ? false : !tok)) // We did not find the requested token!
{
if (failParam) *failParam = ret ? ret->getnum() : 0;
if (noErrors) break; // Caller is OK with a incomplete list of matched strings
@ -6832,7 +6821,6 @@ DefineList *CEXEBuild::searchParseString(const TCHAR *source_string, LineParser&
delete ret;
return NULL;
}
if (maxlen < 0) break;
defout = line.gettoken_str(parmOffs++), src_start = source_string += toklen;
}
return ret;

View file

@ -18,9 +18,7 @@
#include "strlist.h"
#include "utf.h"
#ifndef NDEBUG
#include "util.h" // For PrintColorFmtMsg_ERR
#endif
#ifdef _UNICODE
char* convert_processed_string_to_ansi(char *out, const TCHAR *in, WORD codepage); // defined in build.cpp
@ -300,38 +298,37 @@ DefineList::~DefineList()
struct define *s=(struct define*) m_gr.get();
int num=m_gr.getlen()/sizeof(struct define);
for (int i=0; i<num; i++) {
free(s[i].value);
}
for (int i=0; i<num; i++) free(s[i].value);
}
int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
int DefineList::addn(const TCHAR *name, size_t maxvallen, const TCHAR *value)
{
int pos=SortedStringList<struct define>::add(name);
if (pos == -1)
{
return 1;
}
if (pos == -1) return 1;
size_t cbVal = ++maxvallen * sizeof(TCHAR);
TCHAR **newvalue=&(((struct define*) m_gr.get())[pos].value);
size_t size_in_bytes = (_tcslen(value) + 1) * sizeof(TCHAR);
*newvalue=(TCHAR*)malloc(size_in_bytes);
*newvalue = (TCHAR*)malloc(cbVal);
if (!(*newvalue))
{
extern int g_display_errors;
extern void quit();
if (g_display_errors)
{
PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: DefineList malloc(%lu) failed.\n"), (unsigned long) size_in_bytes);
PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: DefineList malloc(%lu) failed.\n"), BUGBUG64TRUNCATE(unsigned long,cbVal));
}
quit();
}
_tcscpy(*newvalue,value);
my_strncpy(*newvalue, value, maxvallen);
return 0;
}
int DefineList::add(const TCHAR *name, const TCHAR *value/*=_T("")*/)
{
return addn(name, _tcslen(value), value);
}
void DefineList::set(const TCHAR *name, const TCHAR *value/*=_T("")*/)
{
del(name);

View file

@ -476,6 +476,7 @@ class DefineList : public SortedStringList<struct define>
* general program exit with error logging.
*/
int add(const TCHAR *name, const TCHAR *value=_T(""));
int addn(const TCHAR *name, size_t maxvallen, const TCHAR *value); // maxvallen does not include \0
void set(const TCHAR *name, const TCHAR *value=_T(""));
/**

View file

@ -67,21 +67,13 @@ double my_wtof(const wchar_t *str)
return atof(buf);
}
unsigned int my_strncpy(TCHAR*Dest, const TCHAR*Src, unsigned int cchMax)
size_t my_strncpy(TCHAR*Dest, const TCHAR*Src, size_t cchMax)
{
// Dest and Src must be valid, Dest is always \0 terminated.
// Returns number of TCHARs copied to Dest; min(strlen(Src),cchMax-1).
unsigned int cch = 0;
if (cchMax)
{
for(;--cchMax;)
{
TCHAR ch = Src[cch];
if (!ch) break;
Dest[cch++] = ch;
}
Dest[cch] = _T('\0');
}
// Returns number of TCHARs copied to Dest (not counting \0); min(strlen(Src),cchMax-1).
size_t cch = 0;
if (cchMax) for (TCHAR c; --cchMax;) if (!(c = Src[cch])) break; else Dest[cch++] = c;
Dest[cch] = _T('\0');
return cch;
}

View file

@ -33,7 +33,7 @@
#include <stdarg.h>
extern double my_wtof(const wchar_t *str);
extern unsigned int my_strncpy(TCHAR*Dest, const TCHAR*Src, unsigned int cchMax);
extern size_t my_strncpy(TCHAR*Dest, const TCHAR*Src, size_t cchMax);
size_t my_strftime(TCHAR *s, size_t max, const TCHAR *fmt, const struct tm *tm);
// Adds the bitmap in filename using resource editor re as id id.