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
1 changed files with 8 additions and 6 deletions

View File

@ -97,6 +97,7 @@ validateTzEntry(tzEntry *tzentry)
static bool
splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
{
char *brkl;
char *abbrev;
char *offset;
char *offset_endptr;
@ -106,7 +107,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
tzentry->lineno = lineno;
tzentry->filename = filename;
abbrev = strtok(line, WHITESPACE);
abbrev = strtok_r(line, WHITESPACE, &brkl);
if (!abbrev)
{
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);
offset = strtok(NULL, WHITESPACE);
offset = strtok_r(NULL, WHITESPACE, &brkl);
if (!offset)
{
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;
}
is_dst = strtok(NULL, WHITESPACE);
is_dst = strtok_r(NULL, WHITESPACE, &brkl);
if (is_dst && pg_strcasecmp(is_dst, "D") == 0)
{
tzentry->is_dst = true;
remain = strtok(NULL, WHITESPACE);
remain = strtok_r(NULL, WHITESPACE, &brkl);
}
else
{
@ -158,7 +159,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
tzentry->zone = pstrdup(offset);
tzentry->offset = 0 * SECS_PER_HOUR;
tzentry->is_dst = false;
remain = strtok(NULL, WHITESPACE);
remain = strtok_r(NULL, WHITESPACE, &brkl);
}
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 */
char *includeFile = pstrdup(line + strlen("@INCLUDE"));
char *brki;
includeFile = strtok(includeFile, WHITESPACE);
includeFile = strtok_r(includeFile, WHITESPACE, &brki);
if (!includeFile || !*includeFile)
{
GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d",