Browse Source

bug in NULL arrays? NULL Arrays weren't encoded. But part6 - 5.24 says they should be encoded as array with length = -1 @jpfr what do you say?

FlorianPalm 10 years ago
parent
commit
b91474136e
2 changed files with 13 additions and 5 deletions
  1. 3 1
      examples/src/networklayer.c
  2. 10 4
      src/ua_types_encoding_binary.c

+ 3 - 1
examples/src/networklayer.c

@@ -16,7 +16,7 @@ NL_Description NL_Description_TcpBinary  = {
 	NL_UA_ENCODING_BINARY,
 	NL_CONNECTIONTYPE_TCPV4,
 	NL_MAXCONNECTIONS_DEFAULT,
-	{-1,8192,8192,16384,1}
+	{0,8192,8192,16384,1}
 };
 
 /* If we do not have multitasking, we implement a dispatcher-Pattern. All Connections
@@ -209,7 +209,9 @@ void* NL_Connection_init(NL_Connection* c, NL_data* tld, UA_Int32 connectionHand
 	c->connection.connectionHandle = connectionHandle;
 	c->connection.connectionState = CONNECTIONSTATE_CLOSED;
 	c->connection.writerCallback = writer;
+
 	memcpy(&(c->connection.localConf),&(tld->tld->localConf),sizeof(TL_Buffer));
+
 	memset(&(c->connection.remoteConf),0,sizeof(TL_Buffer));
 	UA_String_copy(&(tld->endpointUrl), &(c->connection.localEndpointUrl));
 

+ 10 - 4
src/ua_types_encoding_binary.c

@@ -6,9 +6,12 @@
 /*********/
 
 UA_Int32 UA_Array_calcSizeBinary(UA_Int32 nElements, UA_VTable_Entry *vt, const void *data) {
-	if(vt == UA_NULL || data == UA_NULL)
+	if(vt == UA_NULL){
 		return 0; // do not return error as the result will be used to allocate memory
-
+	}
+	if(data == UA_NULL){ //NULL Arrays are encoded as length = -1
+		return sizeof(UA_Int32);
+	}
 	UA_Int32  length     = sizeof(UA_Int32);
 	UA_UInt32 memSize    = vt->memSize;
 	const UA_Byte *cdata = (const UA_Byte *)data;
@@ -21,9 +24,12 @@ UA_Int32 UA_Array_calcSizeBinary(UA_Int32 nElements, UA_VTable_Entry *vt, const
 
 UA_Int32 UA_Array_encodeBinary(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, UA_ByteString *dst,
                                UA_UInt32 *offset) {
-	if(vt == UA_NULL || src == UA_NULL || dst == UA_NULL || offset == UA_NULL)
+	if(vt == UA_NULL || dst == UA_NULL || offset == UA_NULL)
 		return UA_ERROR;
-
+	if(src == UA_NULL) //Null Arrays are encoded with length = -1 // part 6 - §5.24
+	{
+		noElements = -1;
+	}
 	UA_Int32 retval     = UA_SUCCESS;
 	retval = UA_Int32_encodeBinary(&noElements, dst, offset);
 	const UA_Byte *csrc = (const UA_Byte *)src;