[PATCH 2 of 2] Use strtok_r/strtok_s instead of strtok

Wald Commits scm-commit at wald.intevation.org
Thu Aug 14 11:25:18 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1408008253 -7200
# Node ID 18e3ad073b38b3480a43bdc232f7f83bb9877456
# Parent  d1c951b3012d44b177f913b7144cd8ae33830e0c
Use strtok_r/strtok_s instead of strtok.

    With its global internal state usage of strtok should be
    avoided.
    Patch commited on behalf of Sascha Teichmann.

diff -r d1c951b3012d -r 18e3ad073b38 cinst/mozilla.c
--- a/cinst/mozilla.c	Wed Aug 13 19:35:08 2014 +0200
+++ b/cinst/mozilla.c	Thu Aug 14 11:24:13 2014 +0200
@@ -91,6 +91,12 @@
  */
 #define LINEBUFLEN 10000
 
+#ifdef _WIN32
+#define STRTOK_R strtok_s
+#else
+#define STRTOK_R strtok_r
+#endif
+
 /**
  * @brief Global Return Code
  *
@@ -163,6 +169,7 @@
   char *fqpath;
   bool inprofile = false;
   bool relative_path = false;
+  char *saveptr;
 
   if ((inifile = fopen(inifile_name, "r")) != NULL)
     {
@@ -183,8 +190,9 @@
           /* If we are in a profile parse path related stuff */
           if (inprofile)
             {
-              key = strtok(line, "=");
-              value = strtok(NULL, "=");
+              saveptr = NULL;
+              key = STRTOK_R(line, "=", &saveptr);
+              value = STRTOK_R(NULL, "=", &saveptr);
               str_trim(&value);
               if (str_equal(key, "Path"))
                 {


More information about the Trustbridge-commits mailing list