From 1f4171e20fd3e8b18fda45839880f34801b289ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Fri, 18 Apr 1997 22:08:59 +0200
Subject: [PATCH] Avoid gcc-bug in rc4_set_key

Rev: src/modules/_Crypto/lib/rc4.c:1.6
---
 src/modules/_Crypto/lib/rc4.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/modules/_Crypto/lib/rc4.c b/src/modules/_Crypto/lib/rc4.c
index a15fa8b84f..14f3868a17 100644
--- a/src/modules/_Crypto/lib/rc4.c
+++ b/src/modules/_Crypto/lib/rc4.c
@@ -6,19 +6,20 @@
 #include <rc4.h>
 
 #ifdef RCSID
-RCSID("$Id: rc4.c,v 1.5 1997/03/15 04:52:44 nisse Exp $");
+RCSID("$Id: rc4.c,v 1.6 1997/04/18 20:08:59 nisse Exp $");
 #endif
 
 #define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0)
 
 void rc4_set_key(struct rc4_ctx *ctx, const unsigned INT8 *key, INT32 len)
 {
-  register unsigned INT8 i, j; /* Depends on the eight-bitness of these variables. */
+  register unsigned INT8 j; /* Depends on the eight-bitness of these variables. */
+  unsigned i;
   INT32 k;
 
   /* Initialize context */
   i = 0;
-  do ctx->S[i] = i; while (++i);
+  do ctx->S[i] = i; while (++i < 256);
 
   /* Expand key */
   i = j = k = 0;
@@ -26,7 +27,7 @@ void rc4_set_key(struct rc4_ctx *ctx, const unsigned INT8 *key, INT32 len)
     j += ctx->S[i] + key[k];
     SWAP(ctx->S[i], ctx->S[j]);
     k = (k+1) % len; /* Repeat key if needed */
-  } while(++i);
+  } while(++i < 256);
   
   ctx->i = ctx->j = 0;
 }
-- 
GitLab