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

[PATCH 1/3] sha1_file.c: Fix size_t related printf format warnings

From
Steffen Prohaska <prohaska@zib.de>
Date
Nov 21, 2007, 20:27 UTC
Message-ID
<11956768412804-git-send-email-prohaska@zib.de>
In-Reply-To
<11956768414090-git-send-email-prohaska@zib.de>

The old way of fixing warnings did not succeed on MinGW. MinGW does not support C99 printf format strings for size_t [1]. But gcc on MinGW issues warnings if C99 printf format is not used. Hence, the old stragegy to avoid warnings fails.

[1] http://www.mingw.org/MinGWiki/index.php/C99

This commits passes arguments of type size_t through a tiny helper functions that casts to the type expected by the format string.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 sha1_file.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index f007874..4f68e53 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -25,8 +25,10 @@
 
 #ifdef NO_C99_FORMAT
 #define SZ_FMT "lu"
+static unsigned long sz_fmt(size_t s) { return (unsigned long)s; }
 #else
 #define SZ_FMT "zu"
+static size_t sz_fmt(size_t s) { return s; }
 #endif
 
 const unsigned char null_sha1[20];
@@ -423,9 +425,9 @@ void pack_report(void)
 		"pack_report: getpagesize()            = %10" SZ_FMT "\n"
 		"pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
 		"pack_report: core.packedGitLimit      = %10" SZ_FMT "\n",
-		(size_t) getpagesize(),
-		packed_git_window_size,
-		packed_git_limit);
+		sz_fmt(getpagesize()),
+		sz_fmt(packed_git_window_size),
+		sz_fmt(packed_git_limit));
 	fprintf(stderr,
 		"pack_report: pack_used_ctr            = %10u\n"
 		"pack_report: pack_mmap_calls          = %10u\n"
@@ -435,7 +437,7 @@ void pack_report(void)
 		pack_used_ctr,
 		pack_mmap_calls,
 		pack_open_windows, peak_pack_open_windows,
-		pack_mapped, peak_pack_mapped);
+		sz_fmt(pack_mapped), sz_fmt(peak_pack_mapped));
 }
 
 static int check_packed_git_idx(const char *path,  struct packed_git *p)
-- 
1.5.3.5.750.g8692
Previous: Steffen ProhaskaNext: Steffen Prohaska
Message 2 of 18 in “msysgit fallout”
  1. 0/3 msysgit falloutSteffen Prohaska, Nov 21, 2007
  2. 1/3 sha1_file.c: Fix size_t related printf format warningsSteffen Prohaska, Nov 21, 2007
  3. 2/3 builtin-init-db: use get_git_dir() instead of getenv()Steffen Prohaska, Nov 21, 2007
  4. 3/3 Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir()Steffen Prohaska, Nov 21, 2007
  5. Johannes SchindelinNov 22, 2007
  6. Junio C HamanoNov 22, 2007
  7. Steffen ProhaskaNov 22, 2007
  8. Junio C HamanoNov 22, 2007
  9. Steffen ProhaskaNov 22, 2007
  10. Johannes SixtNov 22, 2007
  11. Steffen ProhaskaNov 22, 2007
  12. Johannes SchindelinNov 22, 2007
  13. Steffen ProhaskaJan 1, 2008
  14. Dmitry KakurinJan 3, 2008
  15. Steffen ProhaskaJan 3, 2008
  16. Dmitry KakurinJan 3, 2008
  17. Steffen ProhaskaJan 3, 2008
  18. Johannes SixtNov 22, 2007

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.