By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,146 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,146 IT Pros & Developers. It's quick & easy.

access violation when unallocating a string

P: n/a
Hi ! I got the fallowing function :

void pushargv(TmpFile in) {
std::string tmp = in.getfilename();
argv.push_back(in.getfilename());
tocleanup.push_back(in.getfilename());}
where argv and tocleanup are vector<string>
I fallowed up the code, and found out that tmp is NOT NULL, however, at the
end of the function, before I get back to the calling function, I get a
access violation (segfault, call it the way you want, a big fat bug), I
searched in the header, and I found out the bug was in xstring, a internal
header for <string> (function name : tidy if it can helps).. I really
doesn't have a clue what's the cause of the problem.. I mean there's
nothing non-standard here.. just a few strings and a vector.. I did that
thousands of time before.. but here I get a bug.. I use VC++ 6.0.. which
is not the best compiler in town for STL and cie.. so it may be a compiler
bug...

thanks a lot !

-Eric
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Eric Boutin" <er**@nic.nac.wdyn.de> wrote in message
news:2G********************@wagner.videotron.net.. .
Hi ! I got the fallowing function :

void pushargv(TmpFile in) {
std::string tmp = in.getfilename();
argv.push_back(in.getfilename());
tocleanup.push_back(in.getfilename());}
where argv and tocleanup are vector<string>
I fallowed up the code, and found out that tmp is NOT NULL,
tmp is a class object. It can't be null, bug or no bug. A pointer can be
null, but not an object.
however, at the
end of the function, before I get back to the calling function, I get a
access violation (segfault, call it the way you want, a big fat bug), I
searched in the header, and I found out the bug was in xstring, a internal
header for <string> (function name : tidy if it can helps).. I really
doesn't have a clue what's the cause of the problem.. I mean there's
nothing non-standard here.. just a few strings and a vector.. I did that
thousands of time before.. but here I get a bug.
You haven't posted enough code to tell what's wrong. What does
TmpFile::getfilename() look like? Did you mean to pass the TmpFile object by
value? That's unusual for an object representing a file. Normally file
objects are passed around by reference, e.g.,

void pushargv(TmpFile &in) // pass by reference
{
// etc.
}

int main()
{
TmpFile file("SomeFile.txt"); // open file
pushargv(file);
}
I use VC++ 6.0.. which
is not the best compiler in town for STL and cie.. so it may be a compiler bug...


I doubt it. That compiler is okay for std::string and std::vector as far as
I know. You say that you've used strings and vectors thousands of times
before. If you were using the same compiler, then don't you think the bug is
more likely in your own code?

DW

Jul 22 '05 #2

P: n/a
"Eric Boutin" <er**@nic.nac.wdyn.de> wrote in message
news:2G********************@wagner.videotron.net.. .
Hi ! I got the fallowing function :

void pushargv(TmpFile in) {
std::string tmp = in.getfilename();
argv.push_back(in.getfilename());
tocleanup.push_back(in.getfilename());}
where argv and tocleanup are vector<string>
I fallowed up the code, and found out that tmp is NOT NULL,
NO SURPRISE, since tmp is an object locally declared.
But you give NO IDEA about what in.getfilename() returns,
so it's hard to judge what's going on here.
however, at the
end of the function, before I get back to the calling function, I get a
access violation (segfault, call it the way you want, a big fat bug), I
searched in the header, and I found out the bug was in xstring,
You mean the result of the bug APPEARED in xstring.
a internal
header for <string> (function name : tidy if it can helps).. I really
doesn't have a clue what's the cause of the problem.. I mean there's
nothing non-standard here..
Except TmpFile, and getfilename.
just a few strings and a vector.. I did that
thousands of time before.. but here I get a bug.. I use VC++ 6.0.. which
is not the best compiler in town for STL and cie.. so it may be a compiler bug...


Or not. We can't know from what you've shown so far. OTOH, many
TENS OF THOUSANDS of programmers have used V6 STL since 1996, and
some have FAILED to get seg faults. Consider...

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #3

P: n/a

"Eric Boutin" <er**@nic.nac.wdyn.de> wrote in message
news:2G********************@wagner.videotron.net.. .
Hi ! I got the fallowing function :

I fallowed up the code, and found out that tmp is NOT NULL, however, at the end of the function, before I get back to the calling function, I get a
access violation (segfault, call it the way you want, a big fat bug), I
searched in the header, and I found out the bug was in xstring, a internal
header for <string> (function name : tidy if it can helps)..


I've used VC 6.0 extensively, and have had no problems with vector<string>.
The problem is more than likely your own code. Tracing back to xstring is
just you finding one of the symptoms of the problem that you've introduced
somewhere else in your code. You can easily corrupt a string or vector
object if you are overwriting memory or doing something else that would lead
to undefined behavior.

Paul
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.