roshbaik2 / open-zwave

Automatically exported from code.google.com/p/open-zwave
0 stars 0 forks source link

crash when trying to access current value of some "list" type ValueID's #381

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Given ValueID v, sometimes when I execute this:

string str_prop_value;
Manager::Get()->GetValueAsString(v, &str_prop_value);

I get the error:

"Expression: vector subscript out of range"

on line 71 of src/value_classes/ValueList.h:

Item const& GetItem()const{ return m_items[m_valueIdx]; }

Here's the call stack:

OpenZWave::ValueList::GetItem() Line 71
OpenZWave::Manager::GetValueAsString(const OpenZWave::ValueID & _id, 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > * o_value) 
Line 2020

When examining "m_items" in the debugger, I note that it is zero length, but 
m_valueIdx is set to 1. So essentially this is a "list" type ValueID, but there 
are no items in the list of possible options. But the code still tries to just 
grab item 1, which is out of range.

I will note that I only seem to get this error BEFORE the 
"Notification::Type_AllNodesQueried" notification event.  So maybe this is by 
design and I'm just trying to access the ValueIDs too early? But I was 
wondering if you'd rather return something like an empty label though in this 
case. Or maybe throw an exception describing what the issue is.

I am using the latest trunk version as of today on Windows 7 in Visual Studio 
2013.

Thanks!

Original issue reported on code.google.com by rkrob...@gmail.com on 26 Oct 2014 at 9:54

GoogleCodeExporter commented 9 years ago
Yep - I can see where this is going wrong. I assume you are accessing once you 
got the ValueAdded Notification for that value?

I need to look a bit deeper into the code path, but will try to fix it up in 
the next release. 

Original comment by jus...@dynam.ac on 5 Dec 2014 at 5:11

GoogleCodeExporter commented 9 years ago

Original comment by jus...@dynam.ac on 8 Dec 2014 at 5:53

GoogleCodeExporter commented 9 years ago
yep correct that is my workaround.

Original comment by rkrob...@gmail.com on 9 Feb 2015 at 6:53