Skip to content

Commit 3f78971

Browse files
ramsay-jonesgitster
authored andcommitted
archive-tar: fix a sparse 'constant too large' warning
Commit dddbad7 ("timestamp_t: a new data type for timestamps", 26-04-2017) introduced a new typedef 'timestamp_t', as a synonym for an unsigned long, which was used at the time to represent timestamps in git. A later commit 28f4aee ("use uintmax_t for timestamps", 26-04-2017) changed the typedef to use an 'uintmax_t' for the timestamp representation type. When building on a 32-bit Linux system, sparse complains that a constant (USTAR_MAX_MTIME) used to detect a 'far-future mtime' timestamp, is too large; 'warning: constant 077777777777UL is so big it is unsigned long long' on lines 335 and 338 of archive-tar.c. Note that both gcc and clang only issue a warning if this constant is used in a context that requires an 'unsigned long' (rather than an uintmax_t). (Since TIME_MAX is no longer equal to 0xFFFFFFFF, even on a 32-bit system, the macro USTAR_MAX_MTIME is set to 077777777777UL, which cannot be represented as an 'unsigned long' constant). In order to suppress the warning, change the definition of the macro constant USTAR_MAX_MTIME to use an 'ULL' type suffix. In a similar vein, on systems which use a 64-bit representation of the 'unsigned long' type, the USTAR_MAX_SIZE constant macro is defined with the value 077777777777ULL. Although this does not cause any warning messages to be issued, it would be more appropriate for this constant to use an 'UL' type suffix rather than 'ULL'. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28f4aee commit 3f78971

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

archive-tar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ static int write_tar_filter_archive(const struct archiver *ar,
2828
#if ULONG_MAX == 0xFFFFFFFF
2929
#define USTAR_MAX_SIZE ULONG_MAX
3030
#else
31-
#define USTAR_MAX_SIZE 077777777777ULL
31+
#define USTAR_MAX_SIZE 077777777777UL
3232
#endif
3333
#if TIME_MAX == 0xFFFFFFFF
3434
#define USTAR_MAX_MTIME TIME_MAX
3535
#else
36-
#define USTAR_MAX_MTIME 077777777777UL
36+
#define USTAR_MAX_MTIME 077777777777ULL
3737
#endif
3838

3939
/* writes out the whole block, but only if it is full */

0 commit comments

Comments
 (0)