[riot-notifications] [RIOT-OS/RIOT] gnrs/pktbuf: avoid memcpy if size <= 0 (#10786)

Martine Lenders notifications at github.com
Wed Jan 16 15:51:09 CET 2019


miri64 requested changes on this pull request.

The `data != NULL` check is still required for the case that `(size > 0) && (data != NULL)` (which is a legal input for uninitialized regions). Without that check the unittests segfault:

```
>>> where
#0  __memcpy_sse2_unaligned () at ../sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S:660
#1  0x08053092 in _create_snip (next=0x0, data=0x0, size=9, type=GNRC_NETTYPE_TEST) at /home/mlenders/Repositories/RIOT-OS/RIOT/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c:383
#2  0x080529fb in gnrc_pktbuf_add (next=0x0, data=0x0, size=9, type=GNRC_NETTYPE_TEST) at /home/mlenders/Repositories/RIOT-OS/RIOT/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c:102
#3  0x0804c0e4 in test_pktbuf_add__pkt_NULL__data_NULL__size_not_0 () at /home/mlenders/Repositories/RIOT-OS/RIOT/tests/unittests/tests-pktbuf/tests-pktbuf.c:134
#4  0x080525fc in TestCase_run (self=0x805beb8 <main_stack+11736>, result=0x8064ac0 <result_>) at /home/mlenders/Repositories/RIOT-OS/RIOT/sys/embunit/TestCase.c:58
#5  0x08052565 in TestCaller_run (self=0x80556c0 <gnrc_pktbuf_tests>, result=0x8064ac0 <result_>) at /home/mlenders/Repositories/RIOT-OS/RIOT/sys/embunit/TestCaller.c:54
#6  0x0804afb4 in TestRunner_runTest (test=0x80556c0 <gnrc_pktbuf_tests>) at /home/mlenders/Repositories/RIOT-OS/RIOT/sys/embunit/TestRunner.c:99
#7  0x08052299 in tests_pktbuf () at /home/mlenders/Repositories/RIOT-OS/RIOT/tests/unittests/tests-pktbuf/tests-pktbuf.c:970
#8  0x0804923f in main () at /home/mlenders/Repositories/RIOT-OS/RIOT/tests/unittests/main.c:35
```

>          memcpy(_data, data, size);
     }
+

Nitpick: Due to the added new lines this function call now unusually sticks out.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10786#pullrequestreview-193172754
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190116/2acfd125/attachment.html>


More information about the notifications mailing list