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

[PATCH] block-sha1/sha1.c: silence compiler complaints by casting void* to uintptr_t

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Aug 14, 2009, 22:52 UTC
Message-ID
<_-0l9qI_nKm-VVtKlL5hzen4bhcyRmiZ1z4jSmKK1LwECXueziRDzSTyacEehOkoqsfYIaEUlds@cipher.nrlssc.navy.mil>
In-Reply-To
<alpine.LFD.2.00.0908130017080.10633@xanadu.home>
From: Brandon Casey <drafnel@gmail.com>

Some compilers produce errors when arithmetic is attempted on pointers to void. So cast to uintptr_t when performing arithmetic on void pointers.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---

This, on top of Nico's last patch "block-sha1: more good unaligned memory access candidates", allows this series to compile and run successfully on Sun Sparc and IRIX MIPS for me.

It produces no differences on Linux using gcc. gcc 3.4.6 and 4.1.2 produce an identical binary for me on x86 and x86-64 with and without this change. Any conceivable negative effects on other arch's?

-brandon
 block-sha1/sha1.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
index e5a1007..ccaba9e 100644
--- a/block-sha1/sha1.c
+++ b/block-sha1/sha1.c
@@ -246,14 +246,14 @@ void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
 		memcpy(lenW + (char *)ctx->W, data, left);
 		lenW = (lenW + left) & 63;
 		len -= left;
-		data += left;
+		data = (const void*) ((uintptr_t) data + left);
 		if (lenW)
 			return;
 		blk_SHA1_Block(ctx, ctx->W);
 	}
 	while (len >= 64) {
 		blk_SHA1_Block(ctx, data);
-		data += 64;
+		data = (const void*) ((uintptr_t) data + 64);
 		len -= 64;
 	}
 	if (len)
-- 
1.6.4
Previous: Nicolas PitreNext: Johannes Schindelin
Message 7 of 15 in “block-sha1: more good unaligned memory access candidates”
  1. block-sha1: more good unaligned memory access candidatesNicolas Pitre, Aug 13, 2009
  2. Linus TorvaldsAug 13, 2009
  3. Nicolas PitreAug 13, 2009
  4. Junio C HamanoAug 13, 2009
  5. Linus TorvaldsAug 13, 2009
  6. Nicolas PitreAug 13, 2009
  7. block-sha1/sha1.c: silence compiler complaints by casting void* to uintptr_tBrandon Casey, Aug 14, 2009
  8. Johannes SchindelinAug 15, 2009
  9. Linus TorvaldsAug 15, 2009
  10. Brandon CaseyAug 15, 2009
  11. Junio C HamanoAug 15, 2009
  12. Brandon CaseyAug 15, 2009
  13. Junio C HamanoAug 15, 2009
  14. Linus TorvaldsAug 15, 2009
  15. Brandon CaseyAug 15, 2009

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.