← Commit list

a61d158d5

Benjamin Robin
Benjamin Robin
2026-08-24
SUCCESS Duration: 150s

Subject

stat: fix negative %X/%Y/%Z timestamps after Y2038 on 32-bit builds

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer      -Iinclude -Iinclude -o applets/usage applets/usage.c

Build Log

(log yok)

Commit Diff GitHub →

coreutils/stat.c+15 -9
@@ -303,12 +303,23 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
}
#endif
+static void FAST_FUNC print_time_t(char *pformat, time_t val)
+{
+#define TYPE_SIGNED(t) ((t) -1 < (t) 0)
+ if (TYPE_SIGNED(time_t)) {
+ strcat(pformat, "lld");
+ printf(pformat, (long long) val);
+ } else {
+ strcat(pformat, "llu");
+ printf(pformat, (unsigned long long) val);
+ }
+}
+
/* print stat info */
static void FAST_FUNC print_stat(char *pformat, const char m,
const char *const filename, const void *data
IF_SELINUX(, security_context_t scontext))
{
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
struct stat *statbuf = (struct stat *) data;
struct passwd *pw_ent;
struct group *gw_ent;
@@ -382,20 +393,15 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
} else if (m == 'x') {
printfs(pformat, human_time(&statbuf->st_atim));
} else if (m == 'X') {
- strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
- /* note: (unsigned long) would be wrong:
- * imagine (unsigned long64)int32 */
- printf(pformat, (long) statbuf->st_atime);
+ print_time_t(pformat, statbuf->st_atime);
} else if (m == 'y') {
printfs(pformat, human_time(&statbuf->st_mtim));
} else if (m == 'Y') {
- strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
- printf(pformat, (long) statbuf->st_mtime);
+ print_time_t(pformat, statbuf->st_mtime);
} else if (m == 'z') {
printfs(pformat, human_time(&statbuf->st_ctim));
} else if (m == 'Z') {
- strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
- printf(pformat, (long) statbuf->st_ctime);
+ print_time_t(pformat, statbuf->st_ctime);
# if ENABLE_SELINUX
} else if (m == 'C' && (option_mask32 & OPT_SELINUX)) {
printfs(pformat, scontext);