Skip to content

Commit 1d4ddb8

Browse files
committed
iterator: cast filesystem iterator entry values explicitly
The filesystem iterator takes `stat` data from disk and puts them into index entries, which use 32 bit ints for time (the seconds portion) and filesize. However, on most systems these are not 32 bit, thus will typically invoke a warning. Most users ignore these fields entirely. Diff and checkout code do use the values, however only for the cache to determine if they should check file modification. Thus, this is not a critical error (and will cause a hash recomputation at worst).
1 parent c6cac73 commit 1d4ddb8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/iterator.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,15 @@ static void filesystem_iterator_set_current(
14851485
filesystem_iterator *iter,
14861486
filesystem_iterator_entry *entry)
14871487
{
1488-
iter->entry.ctime.seconds = entry->st.st_ctime;
1489-
iter->entry.mtime.seconds = entry->st.st_mtime;
1488+
/*
1489+
* Index entries are limited to 32 bit timestamps. We can safely
1490+
* cast this since workdir times are only used in the cache; any
1491+
* mismatch will cause a hash recomputation which is unfortunate
1492+
* but affects only people who set their filetimes to 2038.
1493+
* (Same with the file size.)
1494+
*/
1495+
iter->entry.ctime.seconds = (int32_t)entry->st.st_ctime;
1496+
iter->entry.mtime.seconds = (int32_t)entry->st.st_mtime;
14901497

14911498
#if defined(GIT_USE_NSEC)
14921499
iter->entry.ctime.nanoseconds = entry->st.st_ctime_nsec;
@@ -1501,7 +1508,7 @@ static void filesystem_iterator_set_current(
15011508
iter->entry.mode = git_futils_canonical_mode(entry->st.st_mode);
15021509
iter->entry.uid = entry->st.st_uid;
15031510
iter->entry.gid = entry->st.st_gid;
1504-
iter->entry.file_size = entry->st.st_size;
1511+
iter->entry.file_size = (uint32_t)entry->st.st_size;
15051512

15061513
if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH)
15071514
git_oid_cpy(&iter->entry.id, &entry->id);

0 commit comments

Comments
 (0)