Menu

#960 Issue in hal_queues

18.2.2
closed
None
HAL
Medium
18.2.1
True
2019-02-07
2018-07-11
rushmash
No

Hi, there seems to be a bug in oqWriteTimeout() at hal\src\hal_queues.c

Internal while loop will try to write N bytes to the queue in each iteration, it doesn't take into account number of already written bytes.

The same bug is encountered for iqReadTimeout() function.

Proposed solution:

diff --git a/hal/src/hal_queues.c b/hal/src/hal_queues.c
--- a/hal/src/hal_queues.c
+++ b/hal/src/hal_queues.c
@@ -423,7 +423,7 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,

   osalSysLock();

-  while (rd < n) {
+  while (n) {
     size_t done;

     done = iq_read(iqp, bp, n);
@@ -445,6 +445,7 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
       /* Giving a preemption chance in a controlled point.*/
       osalSysUnlock();

+      n -= done;
       rd += done;
          if (bp != NULL) {
         bp += done;
@@ -708,7 +709,7 @@ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,

   osalSysLock();

-  while (wr < n) {
+  while (n) {
     size_t done;

     done = oq_write(oqp, bp, n);
@@ -730,6 +731,7 @@ size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
       /* Giving a preemption chance in a controlled point.*/
       osalSysUnlock();

+      n -= done;
       wr += done;
       bp += done;

Please take a look.
Thanks!

Discussion

  • Giovanni Di Sirio

    • assigned_to: Giovanni Di Sirio
    • Severity: High --> Medium
    • Fixed in Repository: False --> True
     
  • Giovanni Di Sirio

    Fixed in slightly different way, thanks for reporting.

    Giovanni

     
  • Giovanni Di Sirio

    • Status: open --> closed
     

Log in to post a comment.