aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-05-07 00:21:34 -0500
committerRob Landley <rob@landley.net>2016-05-07 00:21:34 -0500
commit869da8ce3752ce6f5aa63d302eebe60a2b5c8da8 (patch)
tree4e0a4fe101be928c5a85e327ae1641babad586bd
parentd3e8dd1bf56afc2277960472a46907d419e4b3da (diff)
downloadtoybox-869da8ce3752ce6f5aa63d302eebe60a2b5c8da8.tar.gz
Work around increasingly insane compiler developers wanting to make everything
undefined behavior so the optimizer can silently eliminate your entire program.
-rw-r--r--main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main.c b/main.c
index 9c70c961..14c4ff71 100644
--- a/main.c
+++ b/main.c
@@ -137,8 +137,10 @@ void toy_exec(char *argv[])
if (!(which = toy_find(*argv))) return;
// Return if stack depth getting noticeable (proxy for leaked heap, etc).
- if (toys.stacktop && labs((char *)toys.stacktop-(char *)&which)>6000)
- return;
+
+ // Compiler writers have decided subtracting char * is undefined behavior,
+ // so convert to integers. (LP64 says sizeof(long)==sizeof(pointer).)
+ if (toys.stacktop && labs((long)toys.stacktop-(long)&which)>6000) return;
// Return if we need to re-exec to acquire root via suid bit.
if (toys.which && (which->flags&TOYFLAG_ROOTONLY) && toys.wasroot) return;