Move the length decrements in the pipe and endpoint stream functions to the point...
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Pipe.c
index ff4318c..4bd89ec 100644 (file)
@@ -114,7 +114,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -131,6 +131,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream++));\r
+                       Length--;\r
                }\r
        }\r
 \r
@@ -149,7 +150,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -166,6 +167,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream--));\r
+                       Length--;\r
                }\r
        }\r
 \r
@@ -183,7 +185,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -200,6 +202,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length
                else\r
                {\r
                        Pipe_Discard_Byte();\r
+                       Length--;\r
                }\r
        }\r
 \r
@@ -218,7 +221,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -235,6 +238,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream++) = Pipe_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
 \r
@@ -253,7 +257,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -270,6 +274,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream--) = Pipe_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
        \r