[PATCH] obscure code patch
Bob Dunlop
bob.dunlop at xyzzy.org.uk
Tue Aug 17 11:44:29 UTC 2010
Sorry couldn't resist setting that as a subject.
Anyway in obscure_msg() in libbb/obscure.c we have a few lines of code
that read:
if (!++p) {
break; /* move past the matched char if possible */
}
Now since p is a pointer the condition !++p is only going to be true in the
rare case of the pointer wrapping around the top of memory. I think the
original author probably intended !*++p for this conditon.
Since strchr() the core of the loop where this occurs is well behaived when
passed a zero length string we can drop the test and move the increment to
an earlier usage of the pointer.
Saves 4 bytes on my ARM compiler.
Signed-off-by: Bob Dunlop <bob.dunlop at xyzzy.org.uk>
$ diff -Naur busybox-1.17.1{-orig,}/libbb/obscure.c
--- busybox-1.17.1-orig/libbb/obscure.c 2010-07-06 03:25:54.000000000 +0100
+++ busybox-1.17.1/libbb/obscure.c 2010-08-17 12:14:35.000000000 +0100
@@ -130,13 +130,10 @@
p = new_p;
while (1) {
p = strchr(p, new_p[i]);
- if (p == NULL) {
+ if (p++ == NULL) {
break;
}
c++;
- if (!++p) {
- break; /* move past the matched char if possible */
- }
}
if (c >= (length / 2)) {
--
Bob Dunlop
More information about the busybox
mailing list