From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxUx-0004nD-AE for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:22:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcxUs-0005TL-De for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:22:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxUs-0005T2-4t for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:22:46 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id B18852F90F2 for ; Fri, 18 Sep 2015 15:22:45 +0000 (UTC) References: <1442573994-14632-1-git-send-email-marcandre.lureau@redhat.com> <1442573994-14632-4-git-send-email-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: <55FC2C42.2020401@redhat.com> Date: Fri, 18 Sep 2015 17:22:42 +0200 MIME-Version: 1.0 In-Reply-To: <1442573994-14632-4-git-send-email-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 4/4] Replace strotok() by strtok_r() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org On 18/09/2015 12:59, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > block/archipelago.c | 10 +++++----- > block/sheepdog.c | 5 +++-- > qom/cpu.c | 12 ++++++------ > target-i386/cpu.c | 6 +++--- > target-sparc/cpu.c | 10 +++++----- > vl.c | 6 +++--- > 6 files changed, 25 insertions(+), 24 deletions(-) >=20 > diff --git a/block/archipelago.c b/block/archipelago.c > index 855655c..1a8fcc0 100644 > --- a/block/archipelago.c > +++ b/block/archipelago.c > @@ -354,17 +354,17 @@ static void parse_filename_opts(const char *filen= ame, Error **errp, > xport *mport, xport *vport) > { > const char *start; > - char *tokens[4], *ds; > + char *tokens[4], *ds, *save; > int idx; > xport lmport =3D NoPort, lvport =3D NoPort; > =20 > strstart(filename, "archipelago:", &start); > =20 > ds =3D g_strdup(start); > - tokens[0] =3D strtok(ds, "/"); > - tokens[1] =3D strtok(NULL, ":"); > - tokens[2] =3D strtok(NULL, ":"); > - tokens[3] =3D strtok(NULL, "\0"); > + tokens[0] =3D strtok_r(ds, "/", &save); > + tokens[1] =3D strtok_r(NULL, ":", &save); > + tokens[2] =3D strtok_r(NULL, ":", &save); > + tokens[3] =3D strtok_r(NULL, "\0", &save); > =20 > if (!strlen(tokens[0])) { > error_setg(errp, "volume name must be specified first"); > diff --git a/block/sheepdog.c b/block/sheepdog.c > index 67ca788..272a4ca 100644 > --- a/block/sheepdog.c > +++ b/block/sheepdog.c > @@ -1614,12 +1614,13 @@ static int parse_redundancy(BDRVSheepdogState *= s, const char *opt) > { > struct SheepdogInode *inode =3D &s->inode; > const char *n1, *n2; > + char *save; > long copy, parity; > char p[10]; > =20 > pstrcpy(p, sizeof(p), opt); > - n1 =3D strtok(p, ":"); > - n2 =3D strtok(NULL, ":"); > + n1 =3D strtok_r(p, ":", &save); > + n2 =3D strtok_r(NULL, ":", &save); > =20 > if (!n1) { > return -EINVAL; > diff --git a/qom/cpu.c b/qom/cpu.c > index fb80d13a..9511f10 100644 > --- a/qom/cpu.c > +++ b/qom/cpu.c > @@ -42,14 +42,14 @@ bool cpu_exists(int64_t id) > =20 > CPUState *cpu_generic_init(const char *typename, const char *cpu_model= ) > { > - char *str, *name, *featurestr; > + char *str, *name, *featurestr, *save; > CPUState *cpu; > ObjectClass *oc; > CPUClass *cc; > Error *err =3D NULL; > =20 > str =3D g_strdup(cpu_model); > - name =3D strtok(str, ","); > + name =3D strtok_r(str, ",", &save); > =20 > oc =3D cpu_class_by_name(typename, name); > if (oc =3D=3D NULL) { > @@ -60,7 +60,7 @@ CPUState *cpu_generic_init(const char *typename, cons= t char *cpu_model) > cpu =3D CPU(object_new(object_class_get_name(oc))); > cc =3D CPU_GET_CLASS(cpu); > =20 > - featurestr =3D strtok(NULL, ","); > + featurestr =3D strtok_r(NULL, ",", &save); > cc->parse_features(cpu, featurestr, &err); > g_free(str); > if (err !=3D NULL) { > @@ -276,10 +276,10 @@ static void cpu_common_parse_features(CPUState *c= pu, char *features, > Error **errp) > { > char *featurestr; /* Single "key=3Dvalue" string being parsed */ > - char *val; > + char *val, *save; > Error *err =3D NULL; > =20 > - featurestr =3D features ? strtok(features, ",") : NULL; > + featurestr =3D features ? strtok_r(features, ",", &save) : NULL; > =20 > while (featurestr) { > val =3D strchr(featurestr, '=3D'); > @@ -296,7 +296,7 @@ static void cpu_common_parse_features(CPUState *cpu= , char *features, > featurestr); > return; > } > - featurestr =3D strtok(NULL, ","); > + featurestr =3D strtok_r(NULL, ",", &save); > } > } > =20 > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index d2b6bc5..2487641 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -1851,7 +1851,7 @@ static void x86_cpu_parse_featurestr(CPUState *cs= , char *features, > Error **errp) > { > X86CPU *cpu =3D X86_CPU(cs); > - char *featurestr; /* Single 'key=3Dvalue" string being parsed */ > + char *save, *featurestr; /* Single 'key=3Dvalue" string being pars= ed */ > FeatureWord w; > /* Features to be added */ > FeatureWordArray plus_features =3D { 0 }; > @@ -1861,7 +1861,7 @@ static void x86_cpu_parse_featurestr(CPUState *cs= , char *features, > CPUX86State *env =3D &cpu->env; > Error *local_err =3D NULL; > =20 > - featurestr =3D features ? strtok(features, ",") : NULL; > + featurestr =3D features ? strtok_r(features, ",", &save) : NULL; > =20 > while (featurestr) { > char *val; > @@ -1930,7 +1930,7 @@ static void x86_cpu_parse_featurestr(CPUState *cs= , char *features, > error_propagate(errp, local_err); > return; > } > - featurestr =3D strtok(NULL, ","); > + featurestr =3D strtok_r(NULL, ",", &save); > } > =20 > if (cpu->host_features) { > diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c > index 9528e3a..6269091 100644 > --- a/target-sparc/cpu.c > +++ b/target-sparc/cpu.c > @@ -95,7 +95,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const ch= ar *cpu_model) > CPUClass *cc =3D CPU_GET_CLASS(cpu); > CPUSPARCState *env =3D &cpu->env; > char *s =3D g_strdup(cpu_model); > - char *featurestr, *name =3D strtok(s, ","); > + char *featurestr, *name =3D strtok_r(s, ",", &save); > sparc_def_t def1, *def =3D &def1; > Error *err =3D NULL; > =20 > @@ -107,7 +107,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const = char *cpu_model) > env->def =3D g_new0(sparc_def_t, 1); > memcpy(env->def, def, sizeof(*def)); > =20 > - featurestr =3D strtok(NULL, ","); > + featurestr =3D strtok_r(NULL, ",", &save); > cc->parse_features(CPU(cpu), featurestr, &err); > g_free(s); > if (err) { > @@ -560,13 +560,13 @@ static void sparc_cpu_parse_features(CPUState *cs= , char *features, > { > SPARCCPU *cpu =3D SPARC_CPU(cs); > sparc_def_t *cpu_def =3D cpu->env.def; > - char *featurestr; > + char *featurestr, *save; > uint32_t plus_features =3D 0; > uint32_t minus_features =3D 0; > uint64_t iu_version; > uint32_t fpu_version, mmu_version, nwindows; > =20 > - featurestr =3D features ? strtok(features, ",") : NULL; > + featurestr =3D features ? strtok_r(features, ",", &save) : NULL; > while (featurestr) { > char *val; > =20 > @@ -634,7 +634,7 @@ static void sparc_cpu_parse_features(CPUState *cs, = char *features, > "(+feature|-feature|feature=3Dxyz)", feat= urestr); > return; > } > - featurestr =3D strtok(NULL, ","); > + featurestr =3D strtok_r(NULL, ",", &save); > } > cpu_def->features |=3D plus_features; > cpu_def->features &=3D ~minus_features; > diff --git a/vl.c b/vl.c > index 3c6480d..bab2696 100644 > --- a/vl.c > +++ b/vl.c > @@ -1323,16 +1323,16 @@ static int add_semihosting_arg(void *opaque, > /* Use strings passed via -kernel/-append to initialize semihosting.ar= gv[] */ > static inline void semihosting_arg_fallback(const char *file, const ch= ar *cmd) > { > - char *cmd_token; > + char *cmd_token, *save; > =20 > /* argv[0] */ > add_semihosting_arg(&semihosting, "arg", file, NULL); > =20 > /* split -append and initialize argv[1..n] */ > - cmd_token =3D strtok(g_strdup(cmd), " "); > + cmd_token =3D strtok_r(g_strdup(cmd), " ", &save); > while (cmd_token) { > add_semihosting_arg(&semihosting, "arg", cmd_token, NULL); > - cmd_token =3D strtok(NULL, " "); > + cmd_token =3D strtok_r(NULL, " ", &save); > } > } > =20 >=20 Unfortunately mingw doesn't have strtok_r (I think). I have queued v1 of your patches, if you want to write more tests please send them on top. Paolo