[PATCH] [sharutils] Fix swapping on big-endian machines

Petr Písař <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
4.13.1 release replaced SWAP() macro with function. However there were
two bugs. First the function always retuned 0 because it ignored
input argument. Second it indexed input array off-by-one. As
result, shar-1 test failed on S390 or PPC.

This patch fixes it.
---
 lib/md5.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/md5.c b/lib/md5.c
index 076f6ef..6dea827 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -54,10 +54,11 @@ SWAP(md5_uint32 n)
     md5_uint32    uiv;
   } v, res;
 
-  res.cv[0] = v.cv[sizeof(md5_uint32) - 0];
-  res.cv[1] = v.cv[sizeof(md5_uint32) - 1];
-  res.cv[2] = v.cv[sizeof(md5_uint32) - 2];
-  res.cv[3] = v.cv[sizeof(md5_uint32) - 3];
+  v.uiv = n;
+  res.cv[0] = v.cv[sizeof(md5_uint32) - 1];
+  res.cv[1] = v.cv[sizeof(md5_uint32) - 2];
+  res.cv[2] = v.cv[sizeof(md5_uint32) - 3];
+  res.cv[3] = v.cv[sizeof(md5_uint32) - 4];
   return res.uiv;
 }
 
-- 
1.7.11.7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.