aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorChristian Biesinger <cbiesinger@google.com>2019-10-31 16:02:41 -0500
committerChristian Biesinger <cbiesinger@google.com>2019-11-15 11:49:46 -0800
commit53fea9c7e6d4993088016a16be56098fd819cebc (patch)
treeb0bc7dda9acc3a99a84c9c540ee95bf11bf457ba /gdb/nat
parentf8e27d88e4c31089467d8717597c4153723081e6 (diff)
downloadgdb-53fea9c7e6d4993088016a16be56098fd819cebc.zip
gdb-53fea9c7e6d4993088016a16be56098fd819cebc.tar.gz
gdb-53fea9c7e6d4993088016a16be56098fd819cebc.tar.bz2
Use ctime_r and localtime_r for threadsafety
To make these calls threadsafe. localtime_r is provided by gnulib if necessary, and for ctime_r we can just use it because it is in a linux- specific file. gdb/ChangeLog: 2019-11-15 Christian Biesinger <cbiesinger@google.com> * maint.c (scoped_command_stats::print_time): Use localtime_r instead of localtime (provided through gnulib if necessary). * nat/linux-osdata.c (time_from_time_t): Use ctime_r instead of ctime. Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/linux-osdata.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index ca6acd3..d82c062 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -916,7 +916,11 @@ time_from_time_t (char *time, int maxlen, TIME_T seconds)
{
time_t t = (time_t) seconds;
- strncpy (time, ctime (&t), maxlen);
+ /* Per the ctime_r manpage, this buffer needs to be at least 26
+ characters long. */
+ char buf[30];
+ const char *time_str = ctime_r (&t, buf);
+ strncpy (time, time_str, maxlen);
time[maxlen - 1] = '\0';
}
}