sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit a1ff7b4d5bb73127990af3aa50febf707999415f
parent a392952d982e4aae51f7857f8154deb495efc98a
Author: afify <hassan@afify.dev>
Date:   Sat,  4 Jul 2020 18:12:47 +0300

[fix] get_file_date_time validation

- add dt_fmt(date time format)  in config file to config specifier
- strftime return size_t = len of string without the \0
- get_file_date_time return NULL if strftime != (dt_fmt) -1

Diffstat:
Mconfig.def.h | 1+
Msfm.c | 13+++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -52,6 +52,7 @@ static Rule rules[] = { static const size_t move_ud = 10; /* ctrl U, ctrl D movement */ static const mode_t new_dir_perm = 0755; +static const char dt_fmt[] = "%d/%m %I:%M%p"; /* date time format */ /* unicode chars */ static const uint32_t u_cne = 0x2510; diff --git a/sfm.c b/sfm.c @@ -373,15 +373,20 @@ get_file_size(off_t size) static char * get_file_date_time(time_t status) { - char *tim; + char *result; struct tm lt; + size_t result_len; - tim = calloc(14, sizeof(char)); + result_len = (size_t)14; + result = ecalloc(result_len, sizeof(char)); localtime_r(&status, &lt); - strftime(tim, 14, "%d/%m %I:%M%p", &lt); + if (strftime(result, result_len, dt_fmt, &lt) != sizeof(dt_fmt)-1) { + free(result); + return NULL; + } - return tim; + return result; } static char *