# Pointer bug when using xQueueReceive() with non zero xTicksToWait

**URL:** <https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762>\
**Category:** Kernel\
**Created:** [May 11, 2020, 3:11pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762 "2020-05-11T15:11:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_shijj](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@John\_shijj](https://forums.freertos.org/u/John_shijj)\
**Post date:** [May 11, 2020, 3:11pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762/1 "2020-05-11T15:11:27Z")

</div>

Hi,

This problem occurs when I using FreeRTOSv10.2.1 & FreeRTOSv10.3.1. My chip is based on CM0 and IDE is IAR7.4. The bug description is below:

The first time of for loop excute well. Since there is no data in the queue, and then cpu yield to other task.

 ![xQueueSend_bug_p1](https://d2v6vdsk2p900z.cloudfront.net/original/1X/3b8088b475479caa7aa31856668023aff6723372.png)

---

<div class="post-metadata">

**Author:** ![John\_shijj](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@John\_shijj](https://forums.freertos.org/u/John_shijj)\
**Post date:** [May 11, 2020, 3:13pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762/2 "2020-05-11T15:13:34Z")

</div>

When cpu returns to current task, and starts second for loop, the pointer value becomes 0x0, as the picture shows, and it will cause a hardfauld error.

 ![xQueueSend_bug_p2](https://d2v6vdsk2p900z.cloudfront.net/original/1X/4cb474c90b2e6693705c53bd4a609dc99a7368b8.png)

---

<div class="post-metadata">

**Author:** ![John\_shijj](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@John\_shijj](https://forums.freertos.org/u/John_shijj)\
**Post date:** [May 11, 2020, 3:14pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762/3 "2020-05-11T15:14:05Z")

</div>

If I do changes that shows in the follow picture, then the function works properly.

 ![xQueueSend_bug_p3](https://d2v6vdsk2p900z.cloudfront.net/original/1X/8bd499afe49921fb8f5bc8a035a557c17efe6555.png)

Actually, xQueueSend(), xSemaphoreTake(), etc have the same problem in my chip.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 11, 2020, 3:18pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762/4 "2020-05-11T15:18:53Z")

</div>

It is very hard to comment on what might be going wrong from just these three images. Are you suggesting there is a bug in the queue code? Or noting there is a bug in your code you would like help debugging?

---

<div class="post-metadata">

**Author:** ![John\_shijj](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@John\_shijj](https://forums.freertos.org/u/John_shijj)\
**Post date:** [May 11, 2020, 3:32pm UTC](https://forums.freertos.org/t/pointer-bug-when-using-xqueuereceive-with-non-zero-xtickstowait/9762/5 "2020-05-11T15:32:01Z")

</div>

Hi Richard,

Thank you for your reply. This problem doubts me for a long time. I want to know what may be the reason of the problem, or you have any suggestions.
