473,396 Members | 1,975 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,396 software developers and data experts.

string resize problem

Hello,

I am running into something I have never seen before and can't
explain. Hopefully someone can help.

So I have a method that attempts to fill a string with a value with an
istringstream.

istringtream iss;
string str_val;

iss >> str_val;
This gets called hundreds of times and works, but every now and then I
get a bus error. When I run it in the debugger, it fails here - well
actually in the code that gets invoked by this. Below is the STL
method that gets called based on this. The line that is causing the
bus error is the "s.resize(0)" line. How is this possible? Why
doesn't it always fail? What would cause this line to fail? I can't
recreate the problem with a simple program. What would cause
resize() to throw an exception?

Any ideas.

template <class charT, class traits, class Allocator>
istream &
operator>> (istream &is, basic_string <charT, traits, Allocator> &s)
{
int w = is.width (0);
if (is.ipfx0 ())
{
register streambuf *sb = is.rdbuf ();
s.resize (0); <--------------------This causes bus
exception
while (1)
{
int ch = sb->sbumpc ();
Jul 19 '05 #1
1 3017

"Scott" <sc***********@yahoo.com> wrote in message news:b8**************************@posting.google.c om...
Hello,

I am running into something I have never seen before and can't
explain. Hopefully someone can help.

I'd bet a donut that you are screwing up the memory arena elsewhere, writing off the end
of an array allocation or such. The string just gets the side effect
of that when it goes to allocate some memory.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Mrosek | last post by:
Hello, I have the following declaration in an header file (abbreviated version): typedef struct { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char...
3
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the...
5
by: Doug Goulden | last post by:
I have an application library that I have been using for some time with no problems. Yesterday though I started to use part of the library and found that the results were much different than I...
4
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
3
by: Z D | last post by:
Hello, BACKGROUND: ============== I've created a Windows User Control that contains an Image Control (among other controls). The user control handles the picture resize event. Whenever the...
23
by: metaosp | last post by:
Hi, in the following code: string foo("foo"); foo.resize(10); foo.append("bar"); cout << foo << endl; // output is "foo" I expect the output to be "foobar", although "bar" is also
2
by: mrbrightsidestolemymoney | last post by:
Hi, I'm having a problem resizing a (very big) nested vector. It's not the most streamlined piece of code ever but I need this array to avoid having to recalculate the same quantity millions of...
2
by: Mike Cain | last post by:
Two quick questions please: 1) How do I declare a STL string variable that I know in advance I want to hold 5,000 bytes? I'm using SGI STL with MS VS 6.0 C++ in case that matters. For example,...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.