1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Replace remaining strtok() with strtok_r()

for thread-safety in the server in the future

Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: David Steele <david@pgmasters.net>
Discussion: https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org
This commit is contained in:
Peter Eisentraut
2024-07-23 09:13:48 +02:00
parent 4d130b2872
commit 65504b747f

View File

@@ -97,6 +97,7 @@ validateTzEntry(tzEntry *tzentry)
static bool static bool
splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
{ {
char *brkl;
char *abbrev; char *abbrev;
char *offset; char *offset;
char *offset_endptr; char *offset_endptr;
@@ -106,7 +107,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
tzentry->lineno = lineno; tzentry->lineno = lineno;
tzentry->filename = filename; tzentry->filename = filename;
abbrev = strtok(line, WHITESPACE); abbrev = strtok_r(line, WHITESPACE, &brkl);
if (!abbrev) if (!abbrev)
{ {
GUC_check_errmsg("missing time zone abbreviation in time zone file \"%s\", line %d", GUC_check_errmsg("missing time zone abbreviation in time zone file \"%s\", line %d",
@@ -115,7 +116,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
} }
tzentry->abbrev = pstrdup(abbrev); tzentry->abbrev = pstrdup(abbrev);
offset = strtok(NULL, WHITESPACE); offset = strtok_r(NULL, WHITESPACE, &brkl);
if (!offset) if (!offset)
{ {
GUC_check_errmsg("missing time zone offset in time zone file \"%s\", line %d", GUC_check_errmsg("missing time zone offset in time zone file \"%s\", line %d",
@@ -135,11 +136,11 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
return false; return false;
} }
is_dst = strtok(NULL, WHITESPACE); is_dst = strtok_r(NULL, WHITESPACE, &brkl);
if (is_dst && pg_strcasecmp(is_dst, "D") == 0) if (is_dst && pg_strcasecmp(is_dst, "D") == 0)
{ {
tzentry->is_dst = true; tzentry->is_dst = true;
remain = strtok(NULL, WHITESPACE); remain = strtok_r(NULL, WHITESPACE, &brkl);
} }
else else
{ {
@@ -158,7 +159,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
tzentry->zone = pstrdup(offset); tzentry->zone = pstrdup(offset);
tzentry->offset = 0 * SECS_PER_HOUR; tzentry->offset = 0 * SECS_PER_HOUR;
tzentry->is_dst = false; tzentry->is_dst = false;
remain = strtok(NULL, WHITESPACE); remain = strtok_r(NULL, WHITESPACE, &brkl);
} }
if (!remain) /* no more non-whitespace chars */ if (!remain) /* no more non-whitespace chars */
@@ -394,8 +395,9 @@ ParseTzFile(const char *filename, int depth,
{ {
/* pstrdup so we can use filename in result data structure */ /* pstrdup so we can use filename in result data structure */
char *includeFile = pstrdup(line + strlen("@INCLUDE")); char *includeFile = pstrdup(line + strlen("@INCLUDE"));
char *brki;
includeFile = strtok(includeFile, WHITESPACE); includeFile = strtok_r(includeFile, WHITESPACE, &brki);
if (!includeFile || !*includeFile) if (!includeFile || !*includeFile)
{ {
GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d", GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d",