[riot-notifications] [RIOT-OS/RIOT] tests/gnrc_udp: Replace atoi() by strtol(). (#11356)

Juan I Carrano notifications at github.com
Mon Apr 8 18:10:37 CEST 2019

The RIOT community cares a lot about code quality.
Therefore, before describing what your contribution is about, we would like
you to make sure that your modifications are compliant with the RIOT
coding conventions, see https://github.com/RIOT-OS/RIOT/wiki/Coding-conventions.

### Contribution description

atoi() cannot detect errors. Many implementation return zero on error and that is what was being checked here, making the "udp send" command unable to parse integer values of zero. On top of this, the behavior on errors does not seem to be specified in the standard (so it is not even correct to check for zero even when zero is not an accepted value, like for a port number).

The result of all this is that sending UDP packets of zero length (as required by the Release Specs) was not possible.

This patch replaces atoi by strlen, which allows for robust error detection. Sending zero length packets is possible.

### Testing procedure

Run `make -C tests/gnrc_udp all term`

In the RIOT terminal, try to send a 0 length packet:

> udp send fe80::bd:b7e 1337 0
udp send fe80::bd:b7e 1337 0
Error: unable to parse data_len

With this patch:

> udp send fe80::bd:b7e 1337 0
udp send fe80::bd:b7e 1337 0
Success: send 0 byte to [fe80::bd:b7e]:1337

### Issues/PRs references


You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * tests/gnrc_udp: Replace atoi() by strtol().

-- File Changes --

    M tests/gnrc_udp/udp.c (45)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190408/db6f7c7f/attachment.html>

More information about the notifications mailing list