celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject celix git commit: CELIX-405: Fixes incomplete handling of errors in the dfi lib during the parsing of a complex type
Date Thu, 02 Mar 2017 20:00:09 GMT
Repository: celix
Updated Branches:
  refs/heads/develop b6c369907 -> 50ed9f5dc


CELIX-405: Fixes incomplete handling of errors in the dfi lib during the parsing of a complex
type


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/50ed9f5d
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/50ed9f5d
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/50ed9f5d

Branch: refs/heads/develop
Commit: 50ed9f5dc8c63b2ffea6dd0fc3e2b4f076e19498
Parents: b6c3699
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Thu Mar 2 20:59:11 2017 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Thu Mar 2 20:59:11 2017 +0100

----------------------------------------------------------------------
 dfi/private/src/dyn_type.c                      | 49 +++++++++++++-------
 .../test/descriptors/msg_example4.descriptor    | 10 ++++
 dfi/private/test/dyn_message_tests.cpp          | 14 ++++++
 3 files changed, 55 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/50ed9f5d/dfi/private/src/dyn_type.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_type.c b/dfi/private/src/dyn_type.c
index 9beea1d..4fc79ff 100644
--- a/dfi/private/src/dyn_type.c
+++ b/dfi/private/src/dyn_type.c
@@ -284,31 +284,39 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
             TAILQ_INSERT_TAIL(&type->complex.entriesHead, entry, entries);
             status = dynType_parseAny(stream, entry->type);
         } else {
-            if (entry != NULL) {
-                free(entry);
-            }
+            free(entry);
             status = MEM_ERROR;
             LOG_ERROR("Error allocating memory for type");
         }
+
+        if (status != OK) {
+            break;
+        }
+
         c = fgetc(stream);
     }
 
-    entry = TAILQ_FIRST(&type->complex.entriesHead);
-    char *name = NULL;
-    while (c == ' ' && entry != NULL) {
-        status = dynCommon_parseName(stream, &name);
-        if (status == OK) {
-            entry->name = name;
-            entry = TAILQ_NEXT(entry, entries);
-        } else {
-            break;
+
+    if (status == OK) {
+        entry = TAILQ_FIRST(&type->complex.entriesHead);
+        char *name = NULL;
+        while (c == ' ' && entry != NULL) {
+            status = dynCommon_parseName(stream, &name);
+            if (status == OK) {
+                entry->name = name;
+                entry = TAILQ_NEXT(entry, entries);
+            } else {
+                break;
+            }
+            c = getc(stream); 
         }
-        c = getc(stream); 
     }
 
     int count = 0;
-    TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
-        count +=1;
+    if (status == OK) {
+        TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
+            count +=1;
+        }
     }
 
     if (status == OK) {
@@ -322,7 +330,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
             }
         } else {
             status = MEM_ERROR;
-            //T\nODO log: error allocating memory
+            LOG_ERROR("Error allocating memory for elements")
         }
     }
 
@@ -427,14 +435,15 @@ static int dynType_parseRefByValue(FILE *stream, dyn_type *type) {
             LOG_ERROR("Error cannot find type '%s'", name);
         }
         free(name);
+    } 
 
+    if (status ==OK) {
         int c = fgetc(stream);
         if (c != ';') {
             status = PARSE_ERROR;
             LOG_ERROR("Error expected ';' got '%c'", c);
         } 
-    } 
-
+    }
 
     return status;
 }
@@ -835,6 +844,10 @@ const char * dynType_getMetaInfo(dyn_type *type, const char *name) {
 
 ffi_type *dynType_ffiType(dyn_type *type) {
     if (type->type == DYN_TYPE_REF) {
+        if (type->ref.ref == NULL) {
+            LOG_ERROR("Error. Ref for %s is not (yet) initialized", type->name);
+            return NULL;
+        }
         return type->ref.ref->ffiType;
     }
     return type->ffiType;

http://git-wip-us.apache.org/repos/asf/celix/blob/50ed9f5d/dfi/private/test/descriptors/msg_example4.descriptor
----------------------------------------------------------------------
diff --git a/dfi/private/test/descriptors/msg_example4.descriptor b/dfi/private/test/descriptors/msg_example4.descriptor
new file mode 100644
index 0000000..e99e443
--- /dev/null
+++ b/dfi/private/test/descriptors/msg_example4.descriptor
@@ -0,0 +1,10 @@
+:header
+type=message
+name=exmpl4
+version=1.1.0
+:annotations
+:types
+info={Jladditional_info; id info}
+additional_info={Jt; id descr}
+:message
+{Jlinfo; id info}

http://git-wip-us.apache.org/repos/asf/celix/blob/50ed9f5d/dfi/private/test/dyn_message_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp
index 18c5505..f3bbafd 100644
--- a/dfi/private/test/dyn_message_tests.cpp
+++ b/dfi/private/test/dyn_message_tests.cpp
@@ -168,6 +168,16 @@ static void msg_test3(void) {
 	dynMessage_destroy(dynMsg);
 }
 
+static void msg_test4(void) {
+	int status = 0;
+	dyn_message_type *dynMsg = NULL;
+	FILE *desc = fopen("descriptors/msg_example4.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK(status != 0);
+	fclose(desc);
+}
+
 static void msg_invalid(void) {
 	int status = 0;
 	dyn_message_type *dynMsg = NULL;
@@ -234,6 +244,10 @@ TEST(DynMessageTests, msg_test3) {
 	msg_test3();
 }
 
+TEST(DynMessageTests, msg_test4) {
+	msg_test4();
+}
+
 TEST(DynMessageTests, msg_invalid) {
 	msg_invalid();
 }


Mime
View raw message