473,796 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

access violation when unallocating a string

Hi ! I got the fallowing function :

void pushargv(TmpFil e in) {
std::string tmp = in.getfilename( );
argv.push_back( in.getfilename( ));
tocleanup.push_ back(in.getfile name());}
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 1888
"Eric Boutin" <er**@nic.nac.w dyn.de> wrote in message
news:2G******** ************@wa gner.videotron. net...
Hi ! I got the fallowing function :

void pushargv(TmpFil e in) {
std::string tmp = in.getfilename( );
argv.push_back( in.getfilename( ));
tocleanup.push_ back(in.getfile name());}
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::getfil ename() 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(TmpFil e &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.w dyn.de> wrote in message
news:2G******** ************@wa gner.videotron. net...
Hi ! I got the fallowing function :

void pushargv(TmpFil e in) {
std::string tmp = in.getfilename( );
argv.push_back( in.getfilename( ));
tocleanup.push_ back(in.getfile name());}
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.w dyn.de> wrote in message
news:2G******** ************@wa gner.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
2852
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 (access violation at startup) and I can't find the problem. I'm using load time linking and, when I try to step into program execution to find the problem, I don't even get to the start of WinMain before it throws the exception. The source files are...
0
2725
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 violations aren't part of the standard C++ >> exception handling support. On Windows, a particular MSVC compiler >> option enables Microsoft's Structured Exception Handling (SEH) in C++ >> EH so that a catch (...) will catch an access violation. ...
3
1246
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 Advance. #include <ctype.h>
0
1815
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 TabControl to my form and placed a
1
2467
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 expected. My question relates to the memory access violation, specfically, what should happen? My guess is that since the good ole new operator allocates the memory we get an SEH memory access violation exception. Given that this can occur in my...
0
1845
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 access violation - (MSCORWKS.DLL): 0xC0000005: Access Violation. At first I thought it could be due to my C++ code but after quite a lot of investigation I don't think there is nothing wrong with it. The access violation occurs after the destructor...
3
4439
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 do the following and verify what I am seeing (and offer any insight!), I would appreciate it Simply create a new "Win32 Console Project" in VC++ .NET 2003. On the "Application Settings" page, check the "Empty project" box. Click "Finish" Add a...
4
2299
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 http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b172396 But I wonder which stl object can access and which not, I have used std::iostream and std::string this way and seems ok, I know std::map can not, is there any more? The question confused me much.
39
4294
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 just now, I am getting the subject error message (specifically: PHP has encountered an access violation at 00F76E21). The error is NOT occurring on every page request (but it is on most of them) and, when I get the error, simply pressing <F5to...
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.