Skip to content

Commit 729a9b5

Browse files
carenasgitster
authored andcommitted
wrapper: avoid undefined behaviour in macOS
0620b39 ("compat: add a mkstemps() compatibility function", 2009-05-31) included a function based on code from libiberty which would result in undefined behaviour in platforms where timeval's tv_usec is a 32-bit signed type as shown by: wrapper.c:505:31: runtime error: left shift of 594546 by 16 places cannot be represented in type '__darwin_suseconds_t' (aka 'int') interestingly the version of this code from gcc never had this bug and the code had a cast that would had prevented the issue (at least in 64-bit platforms) but was misapplied. change the cast to uint64_t so it also works in 32-bit platforms. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b697d92 commit 729a9b5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
502502
* Try TMP_MAX different filenames.
503503
*/
504504
gettimeofday(&tv, NULL);
505-
value = ((size_t)(tv.tv_usec << 16)) ^ tv.tv_sec ^ getpid();
505+
value = ((uint64_t)tv.tv_usec << 16) ^ tv.tv_sec ^ getpid();
506506
filename_template = &pattern[len - 6 - suffix_len];
507507
for (count = 0; count < TMP_MAX; ++count) {
508508
uint64_t v = value;

0 commit comments

Comments
 (0)