diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-01-27 08:00:11 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-02-01 17:21:39 -0500 |
commit | 5ffa8c818120e35c89becd938d160235c069dd12 (patch) | |
tree | e4a1ce20a003e23618bd54f49cb4acf68aed70cd /src/libsystemd-terminal/subterm.c | |
parent | 294929f8916ca37d89ccb1757868d22f8068c56b (diff) |
Add a snprinf wrapper which checks that the buffer was big enough
If we scale our buffer to be wide enough for the format string, we
should expect that the calculation was correct.
char_array_0() invocations are removed, since snprintf nul-terminates
the output in any case.
A similar wrapper is used for strftime calls, but only in timedatectl.c.
Diffstat (limited to 'src/libsystemd-terminal/subterm.c')
-rw-r--r-- | src/libsystemd-terminal/subterm.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libsystemd-terminal/subterm.c b/src/libsystemd-terminal/subterm.c index 7c119ac58a..63cd2a5ad6 100644 --- a/src/libsystemd-terminal/subterm.c +++ b/src/libsystemd-terminal/subterm.c @@ -161,16 +161,14 @@ static int output_write(Output *o, const void *buf, size_t size) { _printf_(3,0) static int output_vnprintf(Output *o, size_t max, const char *format, va_list args) { - char buf[4096]; + char buf[max]; int r; assert_return(o, -EINVAL); assert_return(format, -EINVAL); - assert_return(max <= sizeof(buf), -EINVAL); + assert_return(max <= 4096, -EINVAL); - r = vsnprintf(buf, max, format, args); - if (r > (ssize_t)max) - r = max; + r = MIN(vsnprintf(buf, max, format, args), (int) max); return output_write(o, buf, r); } |