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

[PATCH 8/9] vcs-svn: suppress a signed/unsigned comparison warning

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 6, 2012, 17:25 UTC
Message-ID
<20120706172528.GI31001@burratino>
In-Reply-To
<20120706171040.GA31001@burratino>
From: Jonathan Nieder <jrnieder@gmail.com>
Date: Thu, 5 Jul 2012 22:21:09 -0500

All callers pass a nonnegative delta_len, so the code is already safe. Add an assertion to ensure that remains so and add a cast to keep clang and gcc -Wsign-compare from worrying.

Reported-by: David Barr <davidbarr@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
v2 suppressed the warning by casting "len" to an off_t, producing an
unintentional change (breakage) in functionality on 64-bit systems
when "len" is large.
This version is longer but more conservative.
 vcs-svn/svndiff.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c
index e810d0c3..74c97c45 100644
--- a/vcs-svn/svndiff.c
+++ b/vcs-svn/svndiff.c
@@ -77,8 +77,9 @@ static int error_short_read(struct line_buffer *input)
 static int read_chunk(struct line_buffer *delta, off_t *delta_len,
 		      struct strbuf *buf, size_t len)
 {
+	assert(*delta_len >= 0);
 	strbuf_reset(buf);
-	if (len > *delta_len ||
+	if (len > (uintmax_t) *delta_len ||
 	    buffer_read_binary(delta, buf, len) != len)
 		return error_short_read(delta);
 	*delta_len -= buf->len;
@@ -290,7 +291,7 @@ error_out:
 int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
 			struct sliding_view *preimage, FILE *postimage)
 {
-	assert(delta && preimage && postimage);
+	assert(delta && preimage && postimage && delta_len >= 0);
 
 	if (read_magic(delta, &delta_len))
 		return -1;
-- 
1.7.10.4
Previous: Jonathan NiederNext: Jonathan Nieder
Message 13 of 16 in “What's cooking in git.git (Jun 2012, #02; Wed, 6)”
  1. Junio C HamanoJun 6, 2012
  2. David Michael BarrJun 6, 2012
  3. Jonathan NiederJun 7, 2012
  4. Junio C HamanoJun 7, 2012
  5. [GIT PULL] vcs-svn housekeepingJonathan Nieder, Jul 6, 2012
  6. 1/9 vcs-svn: drop no-op reset methodsJonathan Nieder, Jul 6, 2012
  7. 2/9 vcs-svn: avoid self-assignment in dummy initialization of pre_offJonathan Nieder, Jul 6, 2012
  8. 3/9 vcs-svn: simplify cleanup in apply_one_windowJonathan Nieder, Jul 6, 2012
  9. 4/9 vcs-svn: use constcmp instead of prefixcmpJonathan Nieder, Jul 6, 2012
  10. 5/9 vcs-svn: use strstr instead of memmemJonathan Nieder, Jul 6, 2012
  11. 6/9 vcs-svn: suppress signed/unsigned comparison warningsJonathan Nieder, Jul 6, 2012
  12. 7/9 vcs-svn: suppress a signed/unsigned comparison warningJonathan Nieder, Jul 6, 2012
  13. 8/9 vcs-svn: suppress a signed/unsigned comparison warningJonathan Nieder, Jul 6, 2012
  14. 9/9 vcs-svn: allow 64-bit Prop-Content-LengthJonathan Nieder, Jul 6, 2012
  15. David Michael BarrJul 6, 2012
  16. Junio C HamanoJul 6, 2012

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.