Browse Source

fixed ymodem internal buffer usage

stefan 11 months ago
parent
commit
8b2cc5cf55
2 changed files with 10 additions and 8 deletions
  1. 8 6
      src/shellmatta_ymodem.c
  2. 2 2
      test/integrationtest/test_integration_ymodem.cpp

+ 8 - 6
src/shellmatta_ymodem.c

@@ -353,10 +353,13 @@ shellmatta_retCode_t shellmatta_ymodem_init(shellmatta_handle_t             hand
         &&  (NULL               != recvPacketCallback)
         &&  (NULL               != transmissionCompleteCallback))
     {
+
+        (void)memset((void *)&inst->ymodem, 0, sizeof(shellmatta_ymodem_t));
+
         /** -# use instances buffer if no buffer is given */
         if(NULL == recvBuffer)
         {
-            if(inst->bufferSize <= YMODEM_PACKET_SIZE_1K)
+            if(inst->bufferSize < YMODEM_PACKET_SIZE_1K)
             {
                 /** -# return use fault if buffer is too small */
                 ret = SHELLMATTA_USE_FAULT;
@@ -366,11 +369,10 @@ shellmatta_retCode_t shellmatta_ymodem_init(shellmatta_handle_t             hand
                 inst->ymodem.packet.packetData = (uint8_t*)inst->buffer;
             }
         }
-
-        (void)memset((void *)&inst->ymodem, 0, sizeof(shellmatta_ymodem_t));
-
-        /** -# store buffer */
-        inst->ymodem.packet.packetData = recvBuffer;
+        else {
+            /** -# store buffer */
+            inst->ymodem.packet.packetData = recvBuffer;
+        }
 
         /** -# init callbacks */
         inst->ymodem.cancelCallback = cancelCallback;

+ 2 - 2
test/integrationtest/test_integration_ymodem.cpp

@@ -89,7 +89,6 @@ SCENARIO("Test successful transmissions in ymodem")
         shellmatta_handle_t handle;
         char buffer[1024u];
         char historyBuffer[1024u];
-        uint8_t ymodemBuffer[1024u];
 
         cancelled = false;
         receivedFileSize = 0u;
@@ -113,11 +112,12 @@ SCENARIO("Test successful transmissions in ymodem")
         WHEN("Starting a ymodem session and passing data.")
         {
             ret = shellmatta_ymodem_init(handle,
-                                         ymodemBuffer,
+                                         NULL,
                                          ymodemCallbackCancel,
                                          ymodemCallbackReceiveHeader,
                                          ymodemCallbackReceivePacket,
                                          ymodemCallbackTransmissionComplete);
+            CHECK(ret == SHELLMATTA_OK);
 
             AND_WHEN("ymodem is polled")
             {