You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/05/14 14:20:17 UTC

[plc4x] branch develop updated: - Fixed the parser - Made sure the spi module is linked to the drivers - Made the test a little more verbose

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 97ba102  - Fixed the parser - Made sure the spi module is linked to the drivers - Made the test a little more verbose
97ba102 is described below

commit 97ba102ce452c9b5de8ab3eeb0fba24f7383bf72
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu May 14 16:20:09 2020 +0200

    - Fixed the parser
    - Made sure the spi module is linked to the drivers
    - Made the test a little more verbose
---
 sandbox/plc4c/drivers/modbus/CMakeLists.txt    |  2 +-
 sandbox/plc4c/drivers/s7/CMakeLists.txt        |  2 +-
 sandbox/plc4c/drivers/simulated/CMakeLists.txt |  2 +-
 sandbox/plc4c/spi/src/system.c                 | 13 +++++++++----
 sandbox/plc4c/spi/test/system_test.c           |  4 ++++
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/sandbox/plc4c/drivers/modbus/CMakeLists.txt b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
index 8237bde..d8227f8 100644
--- a/sandbox/plc4c/drivers/modbus/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/modbus/CMakeLists.txt
@@ -27,4 +27,4 @@ file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/mod
 
 add_library(plc4c-driver-modbus ${sources} ${generatedSources})
 
-target_link_libraries(plc4c-driver-modbus ${CMAKE_DL_LIBS})
\ No newline at end of file
+target_link_libraries(plc4c-driver-modbus plc4c-spi ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/s7/CMakeLists.txt b/sandbox/plc4c/drivers/s7/CMakeLists.txt
index f161dc1..f1f5f3b 100644
--- a/sandbox/plc4c/drivers/s7/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/s7/CMakeLists.txt
@@ -27,4 +27,4 @@ file(GLOB generatedSources "${PLC4C_ROOT_DIR}/target/generated-sources/plc4x/s7/
 
 add_library(plc4c-driver-s7 ${sources} ${generatedSources})
 
-target_link_libraries(plc4c-driver-s7 ${CMAKE_DL_LIBS})
\ No newline at end of file
+target_link_libraries(plc4c-driver-s7 plc4c-spi ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/drivers/simulated/CMakeLists.txt b/sandbox/plc4c/drivers/simulated/CMakeLists.txt
index db48fc0..f46dfd9 100644
--- a/sandbox/plc4c/drivers/simulated/CMakeLists.txt
+++ b/sandbox/plc4c/drivers/simulated/CMakeLists.txt
@@ -24,4 +24,4 @@ file(GLOB sources "src/*.c")
 
 add_library(plc4c-driver-simulated ${sources})
 
-target_link_libraries(plc4c-driver-simulated ${CMAKE_DL_LIBS})
\ No newline at end of file
+target_link_libraries(plc4c-driver-simulated plc4c-spi ${CMAKE_DL_LIBS})
\ No newline at end of file
diff --git a/sandbox/plc4c/spi/src/system.c b/sandbox/plc4c/spi/src/system.c
index ef705a5..25a6672 100644
--- a/sandbox/plc4c/spi/src/system.c
+++ b/sandbox/plc4c/spi/src/system.c
@@ -228,6 +228,7 @@ plc4c_return_code plc4c_system_create_connection(
           // Allocate enough memory to hold the sub-string.
           protocol_code =
               malloc(sizeof(char) * ((i - start_segment_index) + 1));
+          *(protocol_code + (i - start_segment_index)) = '\0';
           // Copy the sub-string to the freshly allocated memory area.
           strncpy(protocol_code, start_segment, (i - start_segment_index));
 
@@ -254,6 +255,7 @@ plc4c_return_code plc4c_system_create_connection(
           // Allocate enough memory to hold the sub-string.
           transport_code =
               malloc(sizeof(char) * ((i - start_segment_index) + 1));
+          *(transport_code + (i - start_segment_index)) = '\0';
           // Copy the sub-string to the freshly allocated memory area.
           strncpy(transport_code, start_segment, (i - start_segment_index));
 
@@ -290,6 +292,7 @@ plc4c_return_code plc4c_system_create_connection(
         // Allocate enough memory to hold the sub-string.
         transport_connect_information =
             malloc(sizeof(char) * ((i - start_segment_index) + 1));
+        *(transport_connect_information + (i - start_segment_index)) = '\0';
         // Copy the sub-string to the freshly allocated memory area.
         strncpy(transport_connect_information, start_segment,
                 (i - start_segment_index));
@@ -306,14 +309,16 @@ plc4c_return_code plc4c_system_create_connection(
         // connect information.
         if (num_question_marks == 0) {
           transport_connect_information =
-              malloc(sizeof(char) * ((i - start_segment_index)) + 1);
+              malloc(sizeof(char) * ((i - start_segment_index)) + 2);
+          *(transport_connect_information + (i - start_segment_index) + 1) = '\0';
           strncpy(transport_connect_information, start_segment,
-                  (i - start_segment_index));
+                  (i - start_segment_index) + 1);
         }
         // I a question-mark was found, this is the parameters section.
         else {
-          parameters = malloc(sizeof(char) * (i - start_segment_index) + 1);
-          strncpy(parameters, start_segment, (i - start_segment_index));
+          parameters = malloc(sizeof(char) * (i - start_segment_index) + 2);
+          *(parameters + (i - start_segment_index) + 1) = '\0';
+          strncpy(parameters, start_segment, (i - start_segment_index) + 1);
         }
       }
     }
diff --git a/sandbox/plc4c/spi/test/system_test.c b/sandbox/plc4c/spi/test/system_test.c
index b973fe4..0ee760a 100644
--- a/sandbox/plc4c/spi/test/system_test.c
+++ b/sandbox/plc4c/spi/test/system_test.c
@@ -31,6 +31,9 @@ void test_system_plc4c_system_create_connection_args(
     char *expected_connection_string, char *expected_protocol_code,
     char *expected_transport_code, char *expected_transport_connect_information,
     char *expected_parameters) {
+
+  printf("Running test with '%s'", connection_string);
+
   plc4c_connection *connection = NULL;
   plc4c_return_code result =
       plc4c_system_create_connection(connection_string, &connection);
@@ -48,6 +51,7 @@ void test_system_plc4c_system_create_connection_args(
     TEST_ASSERT_EQUAL_STRING(expected_parameters, connection->parameters);
     free(connection);
   }
+  printf("OK\n");
 }
 
 void test_system_plc4c_system_create_connection(void) {