Hi, All 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)); } or the last line should be return ((old->from == new->from) && (old->to == new->to) && (old->passive == new->passive) && password_same(old->next, new->next)); or compare old->password with new->password
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)); }
or the last line should be return ((old->from == new->from) && (old->to == new->to) && (old->passive == new->passive) && password_same(old->next, new->next)); or compare old->password with new->password
That probably should be old->next, because otherwise it looks like infinite loop to me. Pavel -- The best software in life is free (not shareware)! Pavel GCM d? s-: !g p?:+ au- a--@ w+ v- C++@ UL+++ L++ N++ E++ W--- M- Y- R+
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@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.
participants (3)
-
Martin Mares -
Pavel Machek -
Zheng Yuan {ZYUAN1}