rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 6393a61c8e9727deed182e362c37ebbd2eacecff
parent 74569aa161fd6d18580f012e413f1024f54d262d
Author: vaplv <vaplv@free.fr>
Date:   Tue, 26 Jul 2022 14:20:22 +0200

Fix time_dump function

The time_dump function wrote a character to the destination string if
its pointer was not NULL, even though the maximum number of characters
that could be written was 0. Also a time of 0 with the flag TIME_DAY not
writing anything to the destination string. This commit fix these bugs.

Diffstat:
Msrc/clock_time.c | 5+++--
Msrc/clock_time.h | 4++--
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/clock_time.c b/src/clock_time.c @@ -157,7 +157,7 @@ time_dump ASSERT(time && (!max_dump_len || dump)); if(real_dump_len) *real_dump_len = 0; - if(dump) dump[0] = '\0'; + if(max_dump_len > 0) dump[0] = '\0'; if(!flag) return; #define DUMP(Time, Suffix) \ @@ -216,7 +216,7 @@ time_dump /* Remove last space */ if(real_dump_len) *real_dump_len -= 1; - if(dump) { + if(max_dump_len > 0) { size_t dump_len = strlen(dump); if(!dump_len && flag) { if(flag & TIME_NSEC) { DUMP(0, "nsec"); @@ -225,6 +225,7 @@ time_dump } else if(flag & TIME_SEC) { DUMP(0, "sec"); } else if(flag & TIME_MIN) { DUMP(0, "min"); } else if(flag & TIME_HOUR) { DUMP(0, "hour"); + } else if(flag & TIME_DAY) { DUMP(0, "day"); } dump_len = strlen(dump); } diff --git a/src/clock_time.h b/src/clock_time.h @@ -72,9 +72,9 @@ RSYS_API void time_dump (const struct time* time, int flag, /* Combination of time_unit or TIME_ALL */ - size_t* real_dump_len, /* May be NULL */ + size_t* real_dump_len, /* May be NULL (wo '\0') */ char* dump, /* May be NULL */ - size_t max_dump_len); + size_t max_dump_len); /* With '\0' */ END_DECLS