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 8784427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:05:14+00:00 2026-06-13T21:05:14+00:00

I’m working with Code::Blocks with MinGW on Windows 7; I have this function that

  • 0

I’m working with Code::Blocks with MinGW on Windows 7;

I have this function that works fine:

Hueso* getSkel(int cual)
{
    unsigned int cont; //SkelCargados and CantSkel are global vectors
    for (cont =0; cont < SkelCargados.size();cont++) if ( CantSkel[cont] == cual) break; // EDIT: I changed <= with < before SkelCargados.size()
    if (SkelCargados.empty() || cont>SkelCargados.size())
    {
        char linea[LINEA]; //LINEA is a macro. Max value for this string.
        FILE * f = fopen("esqueletos.txt","rt");
        if (f == NULL) return NULL;
        fgets (linea,LINEA,f);

        vector<float> puntos_; // <-- please pay attention in these 4 lines
        puntos_.push_back(2.2);
        puntos_.push_back(2.2);
        puntos_.push_back(2.2);

        while (!feof(f))
        {
            //...
        }
        fclose(f);
    }
    return SkelCargados[CantSkel[cont]];
}

And this one, that crashes while trying the 2nd push_back. The (NOT)funny thing is that when I put the vector and its push_back()s before fgets, it behaves normally.

EDIT: If I declare the vector as global variable it works fine too.

bool CargarMapa()
{
    char linea[LINEA];
    FILE * f = fopen("mapas.txt","rt");
    if (f == NULL) return false;
    fgets (linea,LINEA,f);


    vector<float> puntos_;
    puntos_.push_back(2.2);
    puntos_.push_back(3); //Here it crashes
    puntos_.push_back(4.2);


    while (!feof(f))
    {
        //...
    }
    fclose(f);
    return true;
}

This is what happens when it crashes: The debugger throws “Program received signal SIGSEGV, Segmentation fault.” and goes to the line marked with a “HERE IT STOPS” comment, in file “new_allocator.h”:

//(I did not write the following comment)

/*
 @brief  An allocator that uses global new, as per [20.4].
 @ingroup allocators

 This is precisely the allocator defined in the C++ Standard. 
   - all allocation calls operator new
   - all deallocation calls operator delete
*/
template<typename _Tp>
class new_allocator
{
public:
  typedef size_t     size_type;
  typedef ptrdiff_t  difference_type;
  typedef _Tp*       pointer;
  typedef const _Tp* const_pointer;
  typedef _Tp&       reference;
  typedef const _Tp& const_reference;
  typedef _Tp        value_type;

  template<typename _Tp1>
    struct rebind
    { typedef new_allocator<_Tp1> other; };

  new_allocator() throw() { }

  new_allocator(const new_allocator&) throw() { }

  template<typename _Tp1>
    new_allocator(const new_allocator<_Tp1>&) throw() { }

  ~new_allocator() throw() { }

  pointer
  address(reference __x) const { return std::__addressof(__x); }

  const_pointer
  address(const_reference __x) const { return std::__addressof(__x); }

  // NB: __n is permitted to be 0.  The C++ standard says nothing
  // about what the return value is when __n == 0.
  pointer
  allocate(size_type __n, const void* = 0)
  { 
if (__n > this->max_size())
  std::__throw_bad_alloc();

return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); //HERE IT STOPS
  }

Please, help me. 🙁

  • 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-06-13T21:05:15+00:00Added an answer on June 13, 2026 at 9:05 pm
    for (cont =0; cont<=SkelCargados.size();cont++) if ( CantSkel[cont] == cual) break;
    

    is not what you want. You probably wanted to use the comparison operator < instead of <= in your loop termination condition. As written, if there is one item in that vector, you might end up breaking on an index of 1, which would result in you trying to index to position 1 in the vector which only has one position. (Remember, vectors, arrays, and other similar constructs are zero-indexed, so [0] is the first element, [1] is the second, etc.)

    Most likely the bug lies not in the push_back where it actually fails for you, but somewhere else in the code where you corrupted memory (which results in undefined behavior).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT

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.