Re: [PATCH 2/3] sha1: clean pointer arithmetic

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 2/3] sha1: clean pointer arithmetic

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:44

Yann Droneaud [off-list ref] writes:
One memcpy() argument is computed from a pointer added to an integer:
eg. int + pointer. It's unusal.
Let's write it in the correct order: pointer + offset.
Meh.

Both are correct.  Aren't ctx->w[lenW] and lenW[ctx-w] both correct,
even?

quoted hunk
Signed-off-by: Yann Droneaud <redacted>
---
 block-sha1/sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
index c1af112..a7c4470 100644
--- a/block-sha1/sha1.c
+++ b/block-sha1/sha1.c
@@ -246,7 +246,7 @@ void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
 		unsigned int left = 64 - lenW;
 		if (len < left)
 			left = len;
-		memcpy(lenW + (char *)ctx->W, data, left);
+		memcpy((char *)ctx->W + lenW, data, left);
 		lenW = (lenW + left) & 63;
 		if (lenW)
 			return;

Re: [PATCH 2/3] sha1: clean pointer arithmetic

From: Yann Droneaud <hidden>
Date: 2016-06-15 22:54:44

Le mercredi 12 septembre 2012 à 11:37 -0700, Junio C Hamano a écrit :
Yann Droneaud [off-list ref] writes:
quoted
One memcpy() argument is computed from a pointer added to an integer:
eg. int + pointer. It's unusal.
Let's write it in the correct order: pointer + offset.
Meh.

Both are correct.  Aren't ctx->w[lenW] and lenW[ctx-w] both correct,
even?
"correct" in my commit log message should be read as "the way it's used
by most C developer".

It's again a cosmetic fix.

-- 
Yann Droneaud

Re: [PATCH 2/3] sha1: clean pointer arithmetic

From: Bruce Korb <hidden>
Date: 2016-06-15 22:54:44

On Wed, Sep 12, 2012 at 1:50 PM, Yann Droneaud [off-list ref] wrote:
quoted
Both are correct.  Aren't ctx->w[lenW] and lenW[ctx-w] both correct,
even?
"correct" in my commit log message should be read as "the way it's used
by most C developer".

It's again a cosmetic fix.
It's a maintenance fix.  The fewer distractions, the easier it is to understand.
"lenW[ctx-w]" is distracting.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help