git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] archive-tar: fix a sparse 'constant too large' warning

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
May 3, 2017, 23:41 UTC
Message-ID
<252ddd6a-3516-6619-8ea6-d3897f13d93d@ramsayjones.plus.com>

Commit dddbad728c ("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 28f4aee3fb ("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 to use an 'ULL' type suffix.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
Hi Junio,

I try to build git on 32-bit Linux about once a week (but it can sometimes be less often than that!). During tonight's build sparse chirped at me while building the 'next' branch.

This patch was built on top of next.

ATB, Ramsay Jones

 archive-tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/archive-tar.c b/archive-tar.c
index 319a5b1c7..6dddc0cff 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -33,7 +33,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
 #if TIME_MAX == 0xFFFFFFFF
 #define USTAR_MAX_MTIME TIME_MAX
 #else
-#define USTAR_MAX_MTIME 077777777777UL
+#define USTAR_MAX_MTIME 077777777777ULL
 #endif
 
 /* writes out the whole block, but only if it is full */
-- 
2.12.0
Next: Johannes Schindelin
Message 1 of 4 in “archive-tar: fix a sparse 'constant too large' warning”
  1. archive-tar: fix a sparse 'constant too large' warningRamsay Jones, May 3, 2017
  2. Johannes SchindelinMay 4, 2017
  3. Ramsay JonesMay 5, 2017
  4. Junio C HamanoMay 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.