graehl / yaml-cpp-old

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

operator[](int) returning value other than Undefined when index >= size() #253

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Alas, I can't seem to reproduce this problem out of the context of my rather 
complex application. I'm working on some pretty complex data structures defined 
in yaml. I had an issue in my program where a key of a map (defined some three 
levels above the current node) appeared as a scalar value in the output of my 
calculation. After investigation I saw that I didn't check the sequence size 
before using an index to operator[] into it. Adding the check solved my 
problem. So it nearly must be that operator[] was giving a value other than 
Undefined, which is never the case when I try to reproduce the phenomenon on a 
smaller scale. I must say that it only happened once in the large calculation, 
but it did so every time, and also every time the value was the same, retrieved 
from the same node containing it. Changing the name of the key in the input in 
question also changed the scalar value seen in the result, which allowed me to 
narrow the problem down. (I had a lot of keys called "a" during testing.)

Also, at some point during the debugging, some boost assertion failed throwing 
an exception that stated something like "assertion `px != 0' failed", although 
i'm only 80% certain about the boolean operator anymore.
At another point during debugging, a Node::const_iterator over a map, with 
IsMap() succeeding, threw an exception in operator++. I expected the iterator 
to be at Node::end(), but it probably encountered the rogue value.

I was using version 0.5.1 on Linux.

PS: I could be totally off on this, but I can't find another reason for adding 
an "if(index<seq.size())" solving the problem. If you do, please inform me :)

PS2: Great library! Kudos!

Original issue reported on code.google.com by cristian...@telenet.be on 12 Jul 2014 at 7:53

GoogleCodeExporter commented 9 years ago

Original comment by jbe...@gmail.com on 13 Jul 2014 at 1:29

GoogleCodeExporter commented 9 years ago
Sorry for the delay in getting to this.

I'm not sure I follow what happened. Do you have a small example, or at least a 
block of code that demonstrates what you're doing?

Original comment by jbe...@gmail.com on 24 Jan 2015 at 8:56