summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--src/core/core-util.c24
-rw-r--r--tests/unit/core/test-core-util.cpp8
3 files changed, 21 insertions, 12 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index cb06c8df8..4e557ae67 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -64,6 +64,7 @@ Bug fixes::
Tests::
+ * core: fix tests on function strftimeval on Alpine
* core: add tests on mouse events (issue #2082)
* gui: add tests on hotlist functions
* scripts: make tests fail if a compiled scripting plugin fails to load
diff --git a/src/core/core-util.c b/src/core/core-util.c
index 4b95b523e..82b2ece3e 100644
--- a/src/core/core-util.c
+++ b/src/core/core-util.c
@@ -199,15 +199,23 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv)
string_dyn_concat (format2, "%%", -1);
ptr_format += 2;
}
- else if ((ptr_format[0] == '%') && (ptr_format[1] == '.')
- && (ptr_format[2] >= '1') && (ptr_format[2] <= '6'))
+ else if ((ptr_format[0] == '%') && (ptr_format[1] == '.'))
{
- snprintf (str_temp, sizeof (str_temp),
- "%06ld", (long)(tv->tv_usec));
- length = ptr_format[2] - '1' + 1;
- str_temp[length] = '\0';
- string_dyn_concat (format2, str_temp, -1);
- ptr_format += 3;
+ if ((ptr_format[2] >= '1') && (ptr_format[2] <= '6'))
+ {
+ snprintf (str_temp, sizeof (str_temp),
+ "%06ld", (long)(tv->tv_usec));
+ length = ptr_format[2] - '1' + 1;
+ str_temp[length] = '\0';
+ string_dyn_concat (format2, str_temp, -1);
+ ptr_format += 3;
+ }
+ else
+ {
+ ptr_format += 2;
+ if (ptr_format[0])
+ ptr_format++;
+ }
}
else if ((ptr_format[0] == '%') && (ptr_format[1] == 'f'))
{
diff --git a/tests/unit/core/test-core-util.cpp b/tests/unit/core/test-core-util.cpp
index 4f7730a94..3303f751c 100644
--- a/tests/unit/core/test-core-util.cpp
+++ b/tests/unit/core/test-core-util.cpp
@@ -229,13 +229,13 @@ TEST(CoreUtil, Strftimeval)
/* invalid microseconds digits (must be 1-6) */
strcpy (str_time, "test");
- LONGS_EQUAL(23, util_strftimeval (str_time, sizeof (str_time),
+ LONGS_EQUAL(20, util_strftimeval (str_time, sizeof (str_time),
"%Y-%m-%d %H:%M:%S.%.0", &tv));
- STRCMP_EQUAL("2023-12-25 10:29:09.%.0", str_time);
+ STRCMP_EQUAL("2023-12-25 10:29:09.", str_time);
strcpy (str_time, "test");
- LONGS_EQUAL(23, util_strftimeval (str_time, sizeof (str_time),
+ LONGS_EQUAL(20, util_strftimeval (str_time, sizeof (str_time),
"%Y-%m-%d %H:%M:%S.%.7", &tv));
- STRCMP_EQUAL("2023-12-25 10:29:09.%.7", str_time);
+ STRCMP_EQUAL("2023-12-25 10:29:09.", str_time);
/* timestamp */
strcpy (str_time, "test");