changeset 214:5a75f8a21503

Change the format of for loops, gcc4 produces incorrect binaries with the previous code.
author Matt Johnston <matt@ucc.asn.au>
date Fri, 08 Jul 2005 11:30:54 +0000
parents 1a52846ec11f
children aad4b3f58556
files signkey.c
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/signkey.c	Thu Jun 02 22:53:18 2005 +0000
+++ b/signkey.c	Fri Jul 08 11:30:54 2005 +0000
@@ -279,7 +279,7 @@
 	char * ret;
 	hash_state hs;
 	unsigned char hash[MD5_HASH_SIZE];
-	unsigned int h, i;
+	unsigned int i;
 	unsigned int buflen;
 
 	md5_init(&hs);
@@ -296,10 +296,11 @@
 	memset(ret, 'Z', buflen);
 	strcpy(ret, "md5 ");
 
-	for (i = 4, h = 0; i < buflen; i+=3, h++) {
-		ret[i] = hexdig(hash[h] >> 4);
-		ret[i+1] = hexdig(hash[h] & 0x0f);
-		ret[i+2] = ':';
+	for (i = 0; i < MD5_HASH_SIZE; i++) {
+		unsigned int pos = 4 + i*3;
+		ret[pos] = hexdig(hash[i] >> 4);
+		ret[pos+1] = hexdig(hash[i] & 0x0f);
+		ret[pos+2] = ':';
 	}
 	ret[buflen-1] = 0x0;
 
@@ -313,7 +314,7 @@
 	char * ret;
 	hash_state hs;
 	unsigned char hash[SHA1_HASH_SIZE];
-	unsigned int h, i;
+	unsigned int i;
 	unsigned int buflen;
 
 	sha1_init(&hs);
@@ -329,10 +330,11 @@
 
 	strcpy(ret, "sha1 ");
 
-	for (i = 5, h = 0; i < buflen; i+=3, h++) {
-		ret[i] = hexdig(hash[h] >> 4);
-		ret[i+1] = hexdig(hash[h] & 0x0f);
-		ret[i+2] = ':';
+	for (i = 0; i < SHA1_HASH_SIZE; i++) {
+		unsigned int pos = 5 + 3*i;
+		ret[pos] = hexdig(hash[i] >> 4);
+		ret[pos+1] = hexdig(hash[i] & 0x0f);
+		ret[pos+2] = ':';
 	}
 	ret[buflen-1] = 0x0;