Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-07-13 04:15:31 +0400
committerVicent Marti <tanoku@gmail.com>2011-07-13 04:15:31 +0400
commit3dd26d1e36bec9753bee6c8a8f1311d7a0c47972 (patch)
tree3660243ee53690178772d61401e203a3efc00880
parentb16692faa3c39f8342f40ad14c70480b9126614b (diff)
index: Yes, we have to truncate
-rw-r--r--src/index.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/index.c b/src/index.c
index 75471e5f3..2fa9c1922 100644
--- a/src/index.c
+++ b/src/index.c
@@ -921,8 +921,18 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
memset(ondisk, 0x0, disk_size);
- ondisk->ctime.seconds = htonl(entry->ctime.seconds);
- ondisk->mtime.seconds = htonl(entry->mtime.seconds);
+ /**
+ * Yes, we have to truncate.
+ *
+ * The on-disk format for Index entries clearly defines
+ * the time and size fields to be 4 bytes each -- so even if
+ * we store these values with 8 bytes on-memory, they must
+ * be truncated to 4 bytes before writing to disk.
+ *
+ * In 2038 I will be either too dead or too rich to care about this
+ */
+ ondisk->ctime.seconds = htonl((uint32_t)entry->ctime.seconds);
+ ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
ondisk->dev = htonl(entry->dev);
@@ -930,7 +940,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
ondisk->mode = htonl(entry->mode);
ondisk->uid = htonl(entry->uid);
ondisk->gid = htonl(entry->gid);
- ondisk->file_size = htonl(entry->file_size);
+ ondisk->file_size = htonl((uint32_t)entry->file_size);
git_oid_cpy(&ondisk->oid, &entry->oid);