Avoiding stack overflow - alloca is not freed before end of function

This commit is contained in:
Ianos Gnatiuc 2005-11-02 02:09:34 +00:00
parent 502e130b8f
commit b3766501a6
3 changed files with 17 additions and 14 deletions

View File

@ -27,10 +27,6 @@
#include <golded.h>
#include <gesrch.h>
#if defined(__USE_ALLOCA__)
#include <malloc.h>
#endif
// ------------------------------------------------------------------
@ -132,16 +128,7 @@ bool FindString(GMsg* msg, const char* prompt, int what) {
Latin2Local(msg->re);
for (Line *ln = msg->lin; ln; ln = ln->next)
{
#if defined(__USE_ALLOCA__)
char *temp = (char *)alloca(ln->txt.length()+1);
#else
__extension__ char temp[ln->txt.length()+1];
#endif
strcpy(temp, ln->txt.c_str());
Latin2Local(temp);
ln->txt = temp;
}
Latin2Local(ln->txt);
}
// If hit, search again current mail without shortcircuit evaluation

View File

@ -1717,6 +1717,21 @@ void Latin2Local(char *str)
}
// ------------------------------------------------------------------
void Latin2Local(std::string &str)
{
#if defined(__USE_ALLOCA__)
char *temp = (char *)alloca(str.length()+1);
#else
__extension__ char temp[str.length()+1];
#endif
strcpy(temp, str.c_str());
Latin2Local(temp);
str = temp;
}
// ------------------------------------------------------------------
char* XlatStr(char* dest, const char* src, int level, Chs* chrtbl, int qpencoded, bool i51) {

View File

@ -181,6 +181,7 @@ Line* LastLine(Line* line);
void MakeLineIndex(GMsg* msg, int rmargin, bool getvalue, bool header_recode);
void MsgLineReIndex(GMsg* msg, int viewhidden=-1, int viewkludge=-1, int viewquote=-1);
void Latin2Local(char *str);
void Latin2Local(std::string &str);
char* XlatStr(char* dest, const char* src, int level, Chs* chrtbl, int qpencoded=false, bool i51=false);
char* mime_header_decode(char* decoded, const char* encoded, char* charset = NULL);
char* strxmimecpy(char* dest, const char* source, int level, int size, bool detect = false);