* Re: Configtool segfaults
[not found] <4E8C5768.8090804@mailbox.tu-dresden.de>
@ 2011-10-07 15:06 ` Martin Laabs
0 siblings, 0 replies; only message in thread
From: Martin Laabs @ 2011-10-07 15:06 UTC (permalink / raw)
To: eCos Developer List
Hello,
I compiled the configtool on my amd64 system (freebsd). After changing some
int* casts to intptr_t compiling the configtool worked. (Any interests in
the diff?)
However - starting the configtool out of a long directory lead to a
segfault. I traced down the problem to the String::vFormat function
void String::vFormat(LPCTSTR pszFormat, va_list marker)
{
for(int nLength=100;nLength;) {
TCHAR *buf=new TCHAR[1+nLength];
int n=_vsntprintf(buf, nLength, pszFormat, marker );
if(-1==n){
nLength*=2; // NT behavior
} else if (n<nLength){
string::operator=(buf);
nLength=0; // trigger exit from loop
} else {
nLength=n+1; // UNIX behavior generally, or NT behavior when buffer
size exactly matches required length
}
delete [] buf;
}
}
When the for-loop runs the second time (which occurs when the output string
is longer that 100 chars) the _vsntprintf function is called a second time.
This is not allowed because the va_list argument marker has already
consumed during the first call.
Anyway - the coding style of this function seems to be somewhat strange.
Why using the "nLength=0; // trigger exit from loop" instead of calling
exit? However - I'm not very familiar with c++ so it might be the better
way to exit that loop.
Greetings,
Martin Laabs
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-10-07 15:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <4E8C5768.8090804@mailbox.tu-dresden.de>
2011-10-07 15:06 ` Configtool segfaults Martin Laabs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).