From: Alain Spineux Date: Wed, 5 Jun 2024 16:08:10 +0000 (+0200) Subject: Fix #10947 time output without century for locale that use multi bytes utf8 X-Git-Tag: Release-15.0.3~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=902a9c0ebc07e2d07729bbf01ec9432ac84760ba;p=thirdparty%2Fbacula.git Fix #10947 time output without century for locale that use multi bytes utf8 - in Korean strftime("%b") is a 3 unicode char encoded in 5 bytes (in utf8) - before Daemon started 28- 5<9B>2024 15:55, conf reloaded 28- 5월-2024 19:03:10 -after Daemon started 28- 5월-24 15:55, conf reloaded 28- 5월-2024 19:03:10 --- diff --git a/bacula/src/lib/btime.c b/bacula/src/lib/btime.c index 2b6d9b530..e02861df5 100644 --- a/bacula/src/lib/btime.c +++ b/bacula/src/lib/btime.c @@ -123,8 +123,11 @@ char *bstrftime_nc(char *dt, int maxlen, utime_t utime) /* NOTE! since the compiler complains about %y, I use %y and cut the century */ strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm); /* overlay the century */ - p = dt+7; - q = dt+9; + /* search for the second -, because %b can be multi-byte utf8 and more than 3 bytes */ + p = dt + 3; // starting at first byte of %b + while (*p != '-') p++; + p++; + q = p+2; while (*q) { *p++ = *q++; } @@ -154,7 +157,10 @@ char *bstrftime_gmt_iso8601(char *dt, int maxlen, utime_t utime) return dt; } -/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time */ +/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time + * Warning If you don't know the timezone and don't specify the right + * "saving time" you cannot always get the right value. (Alain 2024) + * */ utime_t str_to_utime(char *str) { struct tm tm;