summaryrefslogtreecommitdiffstats
path: root/src/dirn.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-01-25 13:34:21 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2014-01-25 13:34:21 +0100
commit6690fdd45ff41ae44e20ca72dfb2afab39010894 (patch)
tree09b030e2a7b2ae066af0e4c623491ad38624d4ec /src/dirn.c
parent88d86389d5ba46bebb353e81f3ed617b9864b7c9 (diff)
Avoid additional NULL pointer derefence when localtime() failed
Diffstat (limited to 'src/dirn.c')
-rw-r--r--src/dirn.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/dirn.c b/src/dirn.c
index 5397d33..2ba20b9 100644
--- a/src/dirn.c
+++ b/src/dirn.c
@@ -141,16 +141,18 @@ static long int dir_aff_ncurses(disk_t *disk, const partition_t *partition, dir_
wbkgdset(window,' ' | COLOR_PAIR(1));
else if((current_file->status&FILE_STATUS_MARKED)!=0 && has_colors())
wbkgdset(window,' ' | COLOR_PAIR(2));
- if(current_file->td_mtime!=0)
{
- const struct tm *tm_p = localtime(&current_file->td_mtime);
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* May have to use %d instead of %e */
- } else {
- strncpy(datestr, " ",sizeof(datestr));
+ const struct tm *tm_p;
+ if(current_file->td_mtime!=0 && (tm_p = localtime(&current_file->td_mtime))!=NULL)
+ {
+ snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
+ tm_p->tm_mday, monstr[tm_p->tm_mon],
+ 1900 + tm_p->tm_year, tm_p->tm_hour,
+ tm_p->tm_min);
+ /* May have to use %d instead of %e */
+ } else {
+ strncpy(datestr, " ",sizeof(datestr));
+ }
}
mode_string(current_file->st_mode, str);
wprintw(window, "%s %5u %5u ",