smich123 / open-zwave

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

ValueRaw - Data length mismatch for raw data #165

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
During start-up the following (every changing) lines in the OZW_Log.txt are 
seen:
2013-01-24 08:57:14.146 Data length mismatch for raw data. Got 13 bu expected 
10.
2013-01-24 08:57:14.160 Data length mismatch for raw data. Got 13 bu expected 
10.

When checking the code in the file "value_classes/ValueRaw.cpp", the following 
section isn't completely correct:
        char const* str = _valueElement->Attribute( "value" );
        if( str )
        {
                uint8 index = 0;
                while( 1 )
                {
                        char *ep = NULL;
                        uint32 val = (uint32)strtol( str, &ep, 16 );
                        if( str == ep || val >= 256 )
                        {
                                break;
                        }
                        if( index < m_valueLength )
                        {
                                m_value[index] = (uint8)val;
                        }
                        index++;
                        str = ep + 1;
                }

               if( index > m_valueLength )
                {
                        Log::Write( LogLevel_Info, "Data length mismatch for raw data. Got %d bu expected %d.", index, m_valueLength );
                }

Normally this should work like:
2013-01-24 17:31:14.910 CommandClass: 99, index=215, value: 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.911 index=1 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00
2013-01-24 17:31:14.911 index=2 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00
2013-01-24 17:31:14.912 index=3 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.912 index=4 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.912 index=5 val=0 str=0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.913 index=6 val=0 str=0x00 0x00 0x00 0x00
2013-01-24 17:31:14.913 index=7 val=0 str=0x00 0x00 0x00
2013-01-24 17:31:14.922 index=8 val=0 str=0x00 0x00
2013-01-24 17:31:14.923 index=9 val=0 str=0x00
2013-01-24 17:31:14.923 index=10 val=0 str=

When it goes wrong, it looks like below. As you can notice, the "value" is read 
correctly, but parsed wrongly.
2013-01-24 17:31:14.924 CommandClass: 99, index=216, value: 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.924 index=1 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00
2013-01-24 17:31:14.925 index=2 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00
2013-01-24 17:31:14.925 index=3 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.934 index=4 val=0 str=0x00 0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.934 index=5 val=0 str=0x00 0x00 0x00 0x00 0x00
2013-01-24 17:31:14.935 index=6 val=0 str=0x00 0x00 0x00 0x00
2013-01-24 17:31:14.935 index=7 val=0 str=0x00 0x00 0x00
2013-01-24 17:31:14.935 index=8 val=0 str=0x00 0x00
2013-01-24 17:31:14.936 index=9 val=0 str=0x00
2013-01-24 17:31:14.936 index=10 val=0 str=D
2013-01-24 17:31:14.937 index=11 val=13 str=a
2013-01-24 17:31:14.937 index=12 val=10 str=t
2013-01-24 17:31:14.954 Data length mismatch for raw data. Got 12 bu expected 
10.

I am not a C++ expert, but i think the following line:
                       str = ep + 1;

Jumps PAST the length of the string, and then the original #00 in the string is 
bypassed and the code starts processing it "happily" again, until it hits the 
next #00.

Original issue reported on code.google.com by uAle...@gmail.com on 24 Jan 2013 at 5:09

GoogleCodeExporter commented 9 years ago
You called it:

--- cpp/src/value_classes/ValueRaw.cpp  (revision 633)
+++ cpp/src/value_classes/ValueRaw.cpp  (working copy)
@@ -183,11 +183,15 @@
                m_value[index] = (uint8)val;
            }
            index++;
+           if( ep != NULL && *ep == '\0' )
+           {
+               break;
+           }
            str = ep + 1;
        }
        if( index > m_valueLength )
        {
-           Log::Write( LogLevel_Info, "Data length mismatch for raw data. Got %d bu 
expected %d.", index, m_valueLength );
+           Log::Write( LogLevel_Info, "Data length mismatch for raw data. Got %d but 
expected %d.", index, m_valueLength );
        }
    }
    else

Original comment by glsatz on 25 Jan 2013 at 4:45

GoogleCodeExporter commented 9 years ago
I restarted multiple times and the fix works :-)

It is save to submit it into the SVN, only i think the routine "bool 
ValueRaw::SetFromString" needs to be changed too. It has the same (bad?) 
parsing code.

Original comment by uAle...@gmail.com on 25 Jan 2013 at 7:13

GoogleCodeExporter commented 9 years ago
Fixed in r638.

Original comment by glsatz on 10 Feb 2013 at 6:52