commit 34167aa6b0d7d53016b8574b4fe1fac764ddf615 from: Russ Cox date: Tue Mar 04 04:37:12 2008 UTC lib9: gcc-4.2 bug in sprint commit - b32d9d9c2e07681450a7ea1801b07e5727fa39e2 commit + 34167aa6b0d7d53016b8574b4fe1fac764ddf615 blob - 9e3cb63ec060f5859dedb96bf4d89a5626e8e7fd blob + 4155d88597e543f89a4371f78688a5f79771694d --- src/lib9/fmt/sprint.c +++ src/lib9/fmt/sprint.c @@ -16,8 +16,11 @@ sprint(char *buf, char *fmt, ...) /* * on PowerPC, the stack is near the top of memory, so * we must be sure not to overflow a 32-bit pointer. + * + * careful! gcc-4.2 assumes buf+len < buf can never be true and + * optimizes the test away. casting to uintptr works around this bug. */ - if(buf+len < buf) + if((uintptr)buf+len < (uintptr)buf) len = -(uintptr)buf-1; va_start(args, fmt);