Use re-entrant functions in a couple of places

Replace strtok and gmtime with their re-entrant versions. More to come.
This commit is contained in:
Evan Miller
2020-11-12 11:20:05 -05:00
parent 97e1d348f7
commit 1bef1b1dca
2 changed files with 6 additions and 4 deletions

View File

@@ -50,9 +50,10 @@ load_options()
{ {
char *opt; char *opt;
char *s; char *s;
char *ctx;
if (!optset && (s=getenv("MDBOPTS"))) { if (!optset && (s=getenv("MDBOPTS"))) {
opt = strtok(s, ":"); opt = strtok_r(s, ":", &ctx);
while (opt) { while (opt) {
if (!strcmp(opt, "use_index")) opts |= MDB_USE_INDEX; if (!strcmp(opt, "use_index")) opts |= MDB_USE_INDEX;
if (!strcmp(opt, "no_memo")) opts |= MDB_NO_MEMO; if (!strcmp(opt, "no_memo")) opts |= MDB_NO_MEMO;
@@ -70,7 +71,7 @@ load_options()
opts |= MDB_DEBUG_ROW; opts |= MDB_DEBUG_ROW;
opts |= MDB_DEBUG_PROPS; opts |= MDB_DEBUG_PROPS;
} }
opt = strtok(NULL,":"); opt = strtok_r(NULL,":", &ctx);
} }
} }
optset = 1; optset = 1;

View File

@@ -760,8 +760,9 @@ int mdb_sql_find_sargcol(MdbSargNode *node, gpointer data)
* Plain integers are UNIX timestamps for backwards compatibility of parser * Plain integers are UNIX timestamps for backwards compatibility of parser
*/ */
if (col->col_type == MDB_DATETIME && node->val_type == MDB_INT) { if (col->col_type == MDB_DATETIME && node->val_type == MDB_INT) {
struct tm *tm = gmtime((time_t*)&node->value.i); struct tm tm;
mdb_tm_to_date(tm, &node->value.d); gmtime_r((time_t*)&node->value.i, &tm);
mdb_tm_to_date(&tm, &node->value.d);
node->val_type = MDB_DOUBLE; node->val_type = MDB_DOUBLE;
} }
} }