vector push_back passing size from 0 to overflow

Hi, please see the following code and the associated prints. I also add the Argument class below.

Basically, it crashes the second time it goes in the loop because of the memory exploding.

1
2
3
4
5
6
7
8
for (size_t i = 0; i < elements.size(); ++i) {
  Argument a;
  a.setAttribute(attribute);
  a.setValue(value);
  std::cout << _arguments.size() << std::endl;
  _arguments.push_back(a);
  std::cout << _arguments.size() << std::endl;
}


Trace:
0
3689348814741910324
std::bad_alloc() // the mem crash because of excessive vector size


Argument class below (I just removed the functions):

1
2
3
4
5
6
7
8
9
10
class Argument {

    private:
        std::string _attribute;
        std::string _value;
        int _id;
        int _status;
        int _degree;

};
Not enough information.
elements, attribute, value, _arguments are not defined.
Please supply a small compilable example that demonstrates your problem.
What is the definition of _arguments?
Bumping this to just give some insight that might be generally helpful:

3689348814741910324 is 11001100110011001100110011001100110011001100110011001100110100 in base 2.
1100'1100'1100'1100'1100'1100'1100'1100'1100'1100'1100'1100'1100'1100'1101'00

1100 is 'C' in hex.

The last two 0s there might have been from the two attempted allocations?
But basically, whenever you see 'CC' a bunch of times, that's the value that Visual Studio fills in for uninitialized bytes in debug mode.
Last edited on
Topic archived. No new replies allowed.