diff --git a/Docs/src/history.but b/Docs/src/history.but index 3dbc638b..18e81833 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -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) diff --git a/Source/lang.cpp b/Source/lang.cpp index 59d64749..c75d95bc 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -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++ } } diff --git a/Source/script.cpp b/Source/script.cpp index 88e85152..c81a78ad 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3470,13 +3470,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int i; for (i=0;igetnum(); 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; diff --git a/Source/strlist.cpp b/Source/strlist.cpp index 5e0349bc..f9861caa 100644 --- a/Source/strlist.cpp +++ b/Source/strlist.cpp @@ -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::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); diff --git a/Source/strlist.h b/Source/strlist.h index 1d894d5e..c2900c06 100644 --- a/Source/strlist.h +++ b/Source/strlist.h @@ -476,6 +476,7 @@ class DefineList : public SortedStringList * 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("")); /** diff --git a/Source/util.cpp b/Source/util.cpp index 75874bf7..270a883b 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -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; } diff --git a/Source/util.h b/Source/util.h index f249c4d2..d0cd9bce 100644 --- a/Source/util.h +++ b/Source/util.h @@ -33,7 +33,7 @@ #include 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.