473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

access violation when unallocating a string

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
3 1871
"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
"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Allen | last post by:
Hi all, I tried posting to one of the ms.win32 groups and haven't gotten a response yet. It may be my C++ that's at fault anyway so I'll try here too. I wrote a .dll that is misbehaving...
0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
3
by: Dick D | last post by:
Could someone tell me why i get an "access violation" exception when the character at string == newline (0x10) and i try to replace it with a space (0x20)? (see the get_word function) Thanks in...
0
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a...
1
by: BillyO | last post by:
In the attached code fragment I have a buffer overflow and a memory access violation. When I run the code .Net fails to verify the IL because of the buffer overflow and I get an exception as...
0
by: techie | last post by:
I have created an event sink in my ATL COM project. The event sink receives events from a C# component. There is no problem with receiving events but when my COM object is released I get an...
3
by: Binary | last post by:
VC++ .NET 2003: Access violation with /O2 compiler switch; no AV with /O Hi I'm in the process of narrowing down a problem, and I have reduced the code involved to the following If someone could...
4
by: mos | last post by:
Hi! According the article: You may experience an access violation when you access an STL object through a pointer or reference in a different DLL or EXE...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.