Is this func correct?

Martin Mares mj at ucw.cz
Mon Jan 8 12:13:02 CET 2001


Hi!

> Maybe i totally miss the point, is this func correct: int
> password_same(struct password_item *old, struct password_item *new) {
>   if (old == new)
>     return 1;
>   if ((!old) || (!new))
>     return 0;
>   return ((old->from == new->from) &&
> 	  (old->to == new->to) &&
> 	  (old->passive == new->passive) &&
> 	  password_same(old, new));
> }

Well spotted. Here is a fix:

diff -u -r1.7 password.c
--- password.c	2000/05/16 15:02:27	1.7
+++ password.c	2001/01/08 11:12:08
@@ -54,12 +54,19 @@
 int
 password_same(struct password_item *old, struct password_item *new)
 {
-  if (old == new)
-    return 1;
-  if ((!old) || (!new))
-    return 0;
-  return ((old->from == new->from) &&
-	  (old->to == new->to) &&
-	  (old->passive == new->passive) &&
-	  password_same(old, new));
+  for(;;)
+    {
+      if (old == new)
+	return 1;
+      if (!old || !new)
+	return 0;
+      if (old->from    != new->from    ||
+	  old->to      != new->to      ||
+	  old->passive != new->passive ||
+	  old->id      != new->id      ||
+	  strcmp(old->password, new->password))
+	return 0;
+      old = old->next;
+      new = new->next;
+    }
 }

				Have a nice fortnight
-- 
Martin `MJ' Mares   <mj at ucw.cz>   http://atrey.karlin.mff.cuni.cz/~mj/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
Light-year? One-third less calories than a regular year.



More information about the Bird-users mailing list