0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 7.4.1955

Problem:    Using 32-bit Perl with 64-bit time_t causes memory corruption.
            (Christian Brabandt)
Solution:   Use time_T instead of time_t for global variables. (Ken Takata)
This commit is contained in:
Bram Moolenaar
2016-06-26 16:44:24 +02:00
parent d388d2ac8b
commit f4fba6dcd5
8 changed files with 34 additions and 21 deletions

View File

@@ -6070,12 +6070,12 @@ get4c(FILE *fd)
}
/*
* Read 8 bytes from "fd" and turn them into a time_t, MSB first.
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
*/
time_t
time_T
get8ctime(FILE *fd)
{
time_t n = 0;
time_T n = 0;
int i;
for (i = 0; i < 8; ++i)
@@ -6137,11 +6137,11 @@ put_bytes(FILE *fd, long_u nr, int len)
#endif
/*
* Write time_t to file "fd" in 8 bytes.
* Write time_T to file "fd" in 8 bytes.
* Returns FAIL when the write failed.
*/
int
put_time(FILE *fd, time_t the_time)
put_time(FILE *fd, time_T the_time)
{
char_u buf[8];
@@ -6150,26 +6150,26 @@ put_time(FILE *fd, time_t the_time)
}
/*
* Write time_t to "buf[8]".
* Write time_T to "buf[8]".
*/
void
time_to_bytes(time_t the_time, char_u *buf)
time_to_bytes(time_T the_time, char_u *buf)
{
int c;
int i;
int bi = 0;
time_t wtime = the_time;
time_T wtime = the_time;
/* time_t can be up to 8 bytes in size, more than long_u, thus we
/* time_T can be up to 8 bytes in size, more than long_u, thus we
* can't use put_bytes() here.
* Another problem is that ">>" may do an arithmetic shift that keeps the
* sign. This happens for large values of wtime. A cast to long_u may
* truncate if time_t is 8 bytes. So only use a cast when it is 4 bytes,
* truncate if time_T is 8 bytes. So only use a cast when it is 4 bytes,
* it's safe to assume that long_u is 4 bytes or more and when using 8
* bytes the top bit won't be set. */
for (i = 7; i >= 0; --i)
{
if (i + 1 > (int)sizeof(time_t))
if (i + 1 > (int)sizeof(time_T))
/* ">>" doesn't work well when shifting more bits than avail */
buf[bi++] = 0;
else