From 0447c52f0b925da8dc89e684d48edfe09b69a9a9 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 20 Feb 2023 14:41:31 +0100 Subject: [PATCH] Use strtol to parse the TID --- src/emu/thread.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/emu/thread.c b/src/emu/thread.c index 3e64e66..a340c12 100644 --- a/src/emu/thread.c +++ b/src/emu/thread.c @@ -5,6 +5,7 @@ #include "path.h" #include "bay.h" +#include static const char chan_fmt[] = "thread%lu.%s"; static const char *chan_name[] = { @@ -49,7 +50,17 @@ get_tid(const char *id, int *tid) return -1; } - *tid = atoi(tidstr); + char *endptr; + errno = 0; + *tid = strtol(tidstr, &endptr, 10); + if (errno != 0) { + err("strtol failed for '%s':", tidstr); + return -1; + } + if (endptr == tidstr) { + err("no digits in tid string '%s'", tidstr); + return -1; + } return 0; }