summaryrefslogtreecommitdiffstats
path: root/src/lib9/fmt/sprint.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-08-22 15:39:56 +0000
committerrsc <devnull@localhost>2004-08-22 15:39:56 +0000
commit984e353160593b20d1e2944e1f2e9ce2117c8490 (patch)
treed7347f9d2ffa06d1033fb41712257a2001fd4d57 /src/lib9/fmt/sprint.c
parentc8c0df440f1a22effd43023368c801e1351e31ed (diff)
downloadplan9port-984e353160593b20d1e2944e1f2e9ce2117c8490.tar.gz
plan9port-984e353160593b20d1e2944e1f2e9ce2117c8490.zip
PowerPC Linux support from ericvh.
Mainly adding va_copy/va_end. Also fix bug in sprint wrapping around top of memory.
Diffstat (limited to 'src/lib9/fmt/sprint.c')
-rw-r--r--src/lib9/fmt/sprint.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lib9/fmt/sprint.c b/src/lib9/fmt/sprint.c
index 57150c36..ac68851b 100644
--- a/src/lib9/fmt/sprint.c
+++ b/src/lib9/fmt/sprint.c
@@ -18,10 +18,19 @@ int
sprint(char *buf, char *fmt, ...)
{
int n;
+ uint len;
va_list args;
+ len = 1<<30; /* big number, but sprint is deprecated anyway */
+ /*
+ * on PowerPC, the stack is near the top of memory, so
+ * we must be sure not to overflow a 32-bit pointer.
+ */
+ if(buf+len < buf)
+ len = -(uint)buf-1;
+
va_start(args, fmt);
- n = vsnprint(buf, 65536, fmt, args); /* big number, but sprint is deprecated anyway */
+ n = vsnprint(buf, len, fmt, args);
va_end(args);
return n;
}