From: Martin Laabs <martin.laabs@mailbox.tu-dresden.de>
To: eCos Developer List <ecos-devel@ecos.sourceware.org>
Subject: Re: Configtool segfaults
Date: Fri, 07 Oct 2011 15:06:00 -0000 [thread overview]
Message-ID: <4E8F15B5.6060909@mailbox.tu-dresden.de> (raw)
In-Reply-To: <4E8C5768.8090804@mailbox.tu-dresden.de>
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
parent reply other threads:[~2011-10-07 15:06 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <4E8C5768.8090804@mailbox.tu-dresden.de>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E8F15B5.6060909@mailbox.tu-dresden.de \
--to=martin.laabs@mailbox.tu-dresden.de \
--cc=ecos-devel@ecos.sourceware.org \
--cc=uni@martinlaabs.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).