On 27/11/14 23:10, Ben Bacarisse wrote:
> Chicken Mcnuggets <
chi...@mcnuggets.com> writes:
> <snip>
>> I've been playing around with this a little bit this evening and can't
>> get it to work correctly. This is my code so far (I've put it up on
>>
ideone.com because it wraps in a nasty way when posted here directly):
>>
>>
http://ideone.com/TgynzG
>>
>> Unfortunately it throws an out of range exception. This is the actual error:
>>
>> unknown location(0): fatal error in "SCGITest": std::out_of_range:
>> vector::_M_range_check: __n (which is 49) >= this->size() (which is
>> 15)
>
> The code increments an iterator in some specific cases. The for loop
> then *always* increments it. Are you certain that the condition that
> ends the loop (it != raw_scgi_netstring.end()) is going to fire and not
> be "skipped"?
>
I've removed all the the manual iterator increments in the loop and
replaced them with continue (which in hindsight is what I meant to do
originally anyway).
I still get the same error which is unfortunate. I'm a bit stuck here.
I've changed the iterator to a const iterator just to make sure I'm not
doing anything stupid with it by accident and I still get the out of
range exception. I could loop through it manually but that kinda defeats
the purpose of using C++ in the first place. I might as well just write
C style code for this if I do that way which I'm attempting to avoid.
> BTW, the code looks to be making heavy work of parsing out the parts of
> string. The std::string class has lots of member function that can help
> with this sort of task.
>
> <snip>
>
Yeah I started off with std::string and using the const char and string
length constructor but hit the same issue there as I did here with out
of range exceptions. I assumed it was because it was getting confused
with all the NULLs but from the looks of it it was something more than
that since the vector is exhibiting something similar.
I can't keep swapping backwards and forwards. I'll stick with vector
until I can get it working and then I'll think about a string
implementation. I guess I could have a constructor for each so the user
can choose how they want it stored internally if they like. Either way
it can't hurt.