From b867d1adb2e6423c260407338bdc8d698330764e Mon Sep 17 00:00:00 2001 From: Michael Adams Date: Sun, 14 Jan 2024 13:32:14 -0800 Subject: [PATCH] Replaced some lingering uses of strtok in the JPC coder with jas_strtok, since the use of strtok is problematic in multithreading contexts. --- src/libjasper/jpc/jpc_util.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libjasper/jpc/jpc_util.c b/src/libjasper/jpc/jpc_util.c index 4330aed5..de431d1d 100644 --- a/src/libjasper/jpc/jpc_util.c +++ b/src/libjasper/jpc/jpc_util.c @@ -74,6 +74,7 @@ #include "jasper/jas_math.h" #include "jasper/jas_malloc.h" +#include "jasper/jas_string.h" #include #include @@ -95,9 +96,10 @@ int jpc_atoaf(const char *s, int *numvalues, double **values) strncpy(buf, s, sizeof(buf)); buf[sizeof(buf) - 1] = '\0'; n = 0; - if ((cp = strtok(buf, delim))) { + char* saveptr = 0; + if ((cp = jas_strtok(buf, delim, &saveptr))) { ++n; - while ((cp = strtok(0, delim))) { + while ((cp = jas_strtok(0, delim, &saveptr))) { if (*cp != '\0') { ++n; } @@ -112,10 +114,11 @@ int jpc_atoaf(const char *s, int *numvalues, double **values) strncpy(buf, s, sizeof(buf)); buf[sizeof(buf) - 1] = '\0'; n = 0; - if ((cp = strtok(buf, delim))) { + saveptr = 0; + if ((cp = jas_strtok(buf, delim, &saveptr))) { vs[n] = atof(cp); ++n; - while ((cp = strtok(0, delim))) { + while ((cp = jas_strtok(0, delim, &saveptr))) { if (*cp != '\0') { vs[n] = atof(cp); ++n;