On Tue, Aug 09, 2005 at 07:24:08PM +0200, Jonas Fonseca Madsen wrote:
> > + if (n1 == -1) n1 = n2; \
> > + if (n2 == -1) n2 = n1; \
> > + if (n1 > n2) n1 = n2; \
>
> Here, both n1 and n2 can be -1, which means the loop below can be
> endless.
No. There is return on first difference or end of string.
--- src/util/string.c.orig 2005-08-09 16:47:01.450227816 +0200
+++ src/util/string.c 2005-08-09 19:43:27.660879176 +0200
@@ -203,17 +203,16 @@
\
/* TODO: Don't precompute strlen()s but rather make the loop smarter.
* --pasky */ \
- if (n1 == -1) n1 = strlen(s1); \
- if (n2 == -1) n2 = strlen(s2); \
\
- string_assert(errfile, errline, n1 >= 0 && n2 >= 0, c); \
+ if (n1 == -1) n1 = n2; \
+ if (n2 == -1) n2 = n1; \
+ if (n1 != n2) return 1; \
\
- d = n1 - n2; \
- if (d) return d; \
\
- for (p = 0; p < n1 && s1[p] && s2[p]; p++) { \
+ for (p = 0; p != n1; p++) { \
d = t1 - t2; \
if (d) return d; \
+ if (!s1[p]) return 0; \
} \
return 0; \
}
_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev