Преглед изворни кода

no more seg-fault on read service but response still wrong

Leon Urbas пре 11 година
родитељ
комит
03a458f0e8
4 измењених фајлова са 26 додато и 30 уклоњено
  1. 1 1
      src/ua_application.c
  2. 3 2
      src/ua_basictypes.c
  3. 1 1
      src/ua_services_attribute.c
  4. 21 26
      tests/check_memory.c

+ 1 - 1
src/ua_application.c

@@ -57,7 +57,7 @@ void appMockup_init() {
 	UA_Array_new((void**)&(v->value.data),2,UA_STRING);
 	v->value.vt = &UA_[UA_STRING];
 	v->value.arrayLength = 2;
-	v->value.encodingMask = UA_VARIANT_ENCODINGMASKTYPE_ARRAY || UA_STRING_NS0;
+	v->value.encodingMask = UA_VARIANT_ENCODINGMASKTYPE_ARRAY | UA_STRING_NS0;
 	UA_String_copycstring("http://opcfoundation.org/UA/",((UA_String **)(((v)->value).data))[0]);
 	UA_String_copycstring("http://localhost:16664/open62541/",((UA_String **)(((v)->value).data))[1]);
 	v->dataType.encodingByte = UA_NODEIDTYPE_FOURBYTE;

+ 3 - 2
src/ua_basictypes.c

@@ -855,7 +855,7 @@ void UA_NodeId_printf(char* label, const UA_NodeId* node) {
 }
 
 UA_Int32 UA_NodeId_compare(const UA_NodeId *n1, const UA_NodeId *n2) {
-	if (n1->encodingByte != n2->encodingByte || n1->namespace != n2->namespace)
+	if (n1 == UA_NULL || n2 == UA_NULL || n1->encodingByte != n2->encodingByte || n1->namespace != n2->namespace)
 		return FALSE;
 
 	switch (n1->encodingByte & UA_NODEIDTYPE_MASK) {
@@ -1313,7 +1313,7 @@ UA_TYPE_START_ENCODEBINARY(UA_Variant)
 			retval |= src->vt->encodeBinary(src->data[i],pos,dst);
 		}
 	}
-	if (src->encodingMask & UA_VARIANT_ENCODINGMASKTYPE_ARRAY) { // encode array dimension field
+	if (src->encodingMask & UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS) { // encode array dimension field
 		// FIXME: encode array dimension field
 		printf("shit happens - encode array dimension field wanted");
 	}
@@ -1433,6 +1433,7 @@ UA_Int32 UA_DataValue_calcSize(UA_DataValue const * p) {
 	} else { // get decoding size
 		length = sizeof(UA_Byte);
 		if (p->encodingMask & UA_DATAVALUE_ENCODINGMASK_VARIANT) {
+			// FIXME: this one can return with an error value instead of a size
 			length += UA_Variant_calcSize(&(p->value));
 		}
 		if (p->encodingMask & UA_DATAVALUE_ENCODINGMASK_STATUSCODE) {

+ 1 - 1
src/ua_services_attribute.c

@@ -44,7 +44,7 @@ static UA_DataValue * service_read_node(Application *app, const UA_ReadValueId *
 	ns_lock *lock = UA_NULL;
 	DBG_VERBOSE(UA_NodeId_printf("service_read_node - search for ",&(id->nodeId)));
 	UA_Int32 result = get_node(ns, &(id->nodeId), &node, &lock);
-	if(result != UA_SUCCESS) {
+	if(result != UA_SUCCESS || node == UA_NULL) {
 		v->encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
 		v->status = UA_STATUSCODE_BADNODEIDUNKNOWN;
 		return v;

+ 21 - 26
tests/check_memory.c

@@ -56,62 +56,57 @@ END_TEST
 
 START_TEST (encodeShallYieldDecode)
 {
+	// given
 	void *obj1 = UA_NULL, *obj2 = UA_NULL;
 	UA_ByteString msg1, msg2;
-//	UA_ByteString x;
-	UA_Int32 retval, pos;
-
-//	printf("testing idx=%d,name=%s\n",_i,UA_[_i].name);
-// create src object
+	UA_Int32 retval, pos = 0;
 	retval = UA_[_i].new(&obj1);
-//	printf("retval=%d, ",retval); x.length = UA_[_i].calcSize(UA_NULL); x.data = (UA_Byte*) obj1; UA_ByteString_printx_hex("obj1=",&x);
-
-// encode obj into buffer
 	UA_ByteString_newMembers(&msg1,UA_[_i].calcSize(obj1));
-	pos = 0;
 	retval = UA_[_i].encodeBinary(obj1, &pos, &msg1);
-//	printf("retval=%d, ",retval); x.length = pos; x.data = (UA_Byte*) msg1.data; UA_ByteString_printx_hex("msg1=",&x);
-
-// create dst object
+	// when
 	UA_[_i].new(&obj2);
-	pos = 0;
-	retval = UA_[_i].decodeBinary(&msg1, &pos, obj2);
-//	printf("retval=%d, ",retval); x.length = UA_[_i].calcSize(UA_NULL); x.data = (UA_Byte*) obj2; UA_ByteString_printx_hex("obj2=",&x);
+	pos = 0; retval = UA_[_i].decodeBinary(&msg1, &pos, obj2);
 	UA_ByteString_newMembers(&msg2,UA_[_i].calcSize(obj2));
-	pos = 0;
-	retval = UA_[_i].encodeBinary(obj2, &pos, &msg2);
-//	printf("retval=%d, ",retval); x.length = pos; x.data = (UA_Byte*) msg2.data; UA_ByteString_printx_hex("msg2=",&x);
-
+	pos = 0; retval = UA_[_i].encodeBinary(obj2, &pos, &msg2);
+	// then
 	ck_assert_msg(UA_ByteString_compare(&msg1,&msg2)==0,"messages differ idx=%d,name=%s",_i,UA_[_i].name);
 	ck_assert_int_eq(retval,UA_SUCCESS);
+	// finally
+	UA_[_i].delete(obj1);
+	UA_[_i].delete(obj2);
+	UA_ByteString_deleteMembers(&msg1);
+	UA_ByteString_deleteMembers(&msg2);
 }
 END_TEST
 
 START_TEST (decodeShallFailWithTruncatedBufferButSurvive)
 {
+	// given
 	void *obj1 = UA_NULL, *obj2 = UA_NULL;
 	UA_ByteString msg1;
 	UA_Int32 retval, pos;
-
 	retval = UA_[_i].new(&obj1);
 	UA_ByteString_newMembers(&msg1,UA_[_i].calcSize(obj1));
-	pos = 0;
-	retval = UA_[_i].encodeBinary(obj1, &pos, &msg1);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-
+	pos = 0; retval = UA_[_i].encodeBinary(obj1, &pos, &msg1);
+	// when
 	UA_[_i].new(&obj2);
 	pos = 0;
 	msg1.length = msg1.length / 2;
 	retval = UA_[_i].decodeBinary(&msg1, &pos, obj2);
-
+	//then
 	ck_assert_msg(retval!=UA_SUCCESS,"testing %s with half buffer",UA_[_i].name);
 
+	//when
 	pos = 0;
 	msg1.length = msg1.length / 4;
 	retval = UA_[_i].decodeBinary(&msg1, &pos, obj2);
-
+	//then
 	ck_assert_msg(retval!=UA_SUCCESS,"testing %s with quarter buffer",UA_[_i].name);
 
+	//finally
+	UA_[_i].delete(obj1);
+	UA_[_i].delete(obj2);
+	UA_ByteString_deleteMembers(&msg1);
 }
 END_TEST