Skip to content

Commit

Permalink
Replaced some lingering uses of strtok in the JPC coder with jas_strtok,
Browse files Browse the repository at this point in the history
since the use of strtok is problematic in multithreading contexts.
  • Loading branch information
mdadams committed Jan 14, 2024
1 parent 2ba5f1c commit b867d1a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libjasper/jpc/jpc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

#include "jasper/jas_math.h"
#include "jasper/jas_malloc.h"
#include "jasper/jas_string.h"

#include <assert.h>
#include <string.h>
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit b867d1a

Please sign in to comment.