]> git.saurik.com Git - apt.git/commitdiff
aptconfiguration: Convert strtok() to strtok_r()
authorJulian Andres Klode <jak@debian.org>
Fri, 23 Oct 2015 18:39:56 +0000 (20:39 +0200)
committerJulian Andres Klode <jak@debian.org>
Fri, 30 Oct 2015 13:20:11 +0000 (14:20 +0100)
strtok() is not thread-safe, whereas strtok_r() is.

Gbp-Dch: ignore

apt-pkg/aptconfiguration.cc

index 69f6f6f8d39d02642c3b7f33f36ae50156bf32ae..c15332c7a95ac8bcf3ad7e9d1d47a16c7f286add 100644 (file)
@@ -382,8 +382,9 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
                FILE *dpkg = fdopen(external[0], "r");
                if(dpkg != NULL) {
                        char buf[1024];
+                       char *tok_buf;
                        while (fgets(buf, sizeof(buf), dpkg) != NULL) {
-                               char* arch = strtok(buf, " ");
+                               char* arch = strtok_r(buf, " ", &tok_buf);
                                while (arch != NULL) {
                                        for (; isspace(*arch) != 0; ++arch);
                                        if (arch[0] != '\0') {
@@ -393,7 +394,7 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
                                                if (std::find(archs.begin(), archs.end(), a) == archs.end())
                                                        archs.push_back(a);
                                        }
-                                       arch = strtok(NULL, " ");
+                                       arch = strtok_r(NULL, " ", &tok_buf);
                                }
                        }
                        fclose(dpkg);