Use of strtok() in dpdk code
Stephen Hemminger
stephen at networkplumber.org
Tue Oct 22 03:08:20 CEST 2024
On Mon, 21 Oct 2024 21:30:02 +0300
Isaac Boukris <iboukris at gmail.com> wrote:
> Hello,
>
> I was debugging a crash resulting from strtok() returning NULL
> unexpectedly (string still had tokens and delimiters), and the only
> explanation I could come up with was that strtok is thread-unsafe and
> another thread could have been calling it at the same time, and so I
> changed it to use strtok_r().
>
> That said, the only other possible use of strtok() that I could find
> was in the dpdk code (telemetry), which brings me to my question,
> should we consider changing all occurrences to strtok_r() or am I
> missing something? there seem to be quite some in non-initialization
> code.
>
> Thanks!
Most of the uses are in tests and other single threaded code.
In general, simpler just to use strtok_r everywhere and not worry about it.
Similar to not using sprintf() and instead using snprintf().
Some code scanners like codeql also flag this.
More information about the dev
mailing list