Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:56:43+00:00 2026-05-30T17:56:43+00:00

I am currently debugging a sizable program. When I come to the following line

  • 0

I am currently debugging a sizable program. When I come to the following line of code:

value->binary_string = value_it->binary_string.substr(range->msb->value, range->size);

The program does not behave correctly. Here value is a pointer to a struct with a member named binary_string with type std::string. When I reach this line while debugging, I see that:

value_it->binary_string = "00000000000000000000000000000111"
range->msb->value = 0
range->size = 32

After this line of code executes, value->binary_string is empty! I have even changed the line to

value->binary_string = value_it->binary_string

and it still fails!

When I reach this line while debugging, my program is using about 100 Mb of memory, so I don’t think it is a memory issue (though I am running Valgrind as we speak to verify this). I am using Ubuntu 11.10, g++-4.6 and libstdc++6.

Has anyone encountered something like this before? I have no idea why my strings aren’t working!

Thanks,

Sam

EDIT1:

The type of value is NumberInst, defined below:

typedef std::string String;

struct NumberInst
{
    unsigned size;
    bool signed_;
    String binary_string;
    bool valid;
    unsigned value;

    NumberInst();
};

EDIT2:

It looks like I’ve narrowed down the search a little bit. While debugging, I tried a few print commands:

print value_it->binary_string
"00000000000000000000000000000111"
print value_it->binary_string[31]
'1'
print value_it->binary_string.substr(0, String::npos)
""
print value_it->binary_string.substr(0, 1)
""

It seems that substr is not working properly in this context. However, when I tested substr in my main function, it seemed to work okay.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:56:45+00:00Added an answer on May 30, 2026 at 5:56 pm

    The problem was caused by a very subtle bug. Somewhere in my project:

    NumberInst* number = new NumberInst;
    number->binary_string.reserve(size);
    for (unsigned i = 0; i < size; i++)
        number->binary_string[i] = ...;
    

    A std::out_of_range exception will not be thrown because I am assuming the standard library compares the array index with the capacity of the string (as opposed to the size of the string). Calling print in a debugger will succeed, because it probably iterates through the buffer until it reaches the ‘\0’ character. However

    String str = number->binary_string
    

    will fail because it is likely that the standard library copies the buffer of value_it->binary_string from [0, size) and adds a ‘\0’ character. Since the size of value_it->binary_string is 0, copying its contents will fail (as will substr and other functions that rely on the size of the calling string).

    In other words, the problem was caused by calling

    str.reserve(size);
    

    instead of

    str.resize(size);
    

    Thanks for your help everyone!

    Sam

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently debugging some fairly complex persistence code, and trying to increase test coverage
When I start debugging the project we are currently working on, the program window
I am currently debugging someone else's code that flips the ups and downs relative
Somewhere in our Ruby code, there are three lines that (currently, for debugging purposes)
i need help in debugging my code. Im new into php and im currently
I am currently debugging code that sometimes works and sometimes does not. It is
Background: I'm currently debugging an application written over a custom-built GUI framework in C++.
I'm currently debugging an ASP.NET MVC application that was just deployed to a different
I'm currently debugging an Ms SQL Function (SQL 2008). In this function, I have
I'm using Visual Studio 2008 to develop ASP.NET applications. Currently I'm debugging with running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.