[Pkg-privacy-commits] [libotr] 193/225: Refactor otrl_mem_differ()

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:45:30 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository libotr.

commit 3a8bd35d0d4ff205c107f706de48ba744fedc16d
Author: jvoisin <julien.voisin at dustri.org>
Date:   Mon Apr 21 15:16:50 2014 +0200

    Refactor otrl_mem_differ()
    
    Using a convoluted while loop that changes the len variable is not
    recommended.
    
    Also, make the diff volatile so we are sure the compiler does not do
    some unwanted optimization.
    
    Acked-by: David Goulet <dgoulet at ev0ke.net>
    
    Slightly tweaked by Ian Goldberg <ian at cypherpunks.ca>
    
    Fixes #22
---
 src/mem.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/mem.c b/src/mem.c
index f703606..09029b7 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -169,12 +169,11 @@ void otrl_mem_init(void)
 int otrl_mem_differ(const unsigned char *buf1, const unsigned char *buf2,
     size_t len)
 {
-    unsigned char diff = 0;
-    while (len) {
-	diff |= ((*buf1) ^ (*buf2));
-	++buf1;
-	++buf2;
-	--len;
+    volatile unsigned char diff = 0;
+    size_t i;
+
+    for (i = 0; i < len; ++i) {
+        diff |= (buf1[i] ^ buf2[i]);
     }
     return (diff != 0);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libotr.git



More information about the Pkg-privacy-commits mailing list