diff options
author | Richard Fitzgerald <rf@opensource.cirrus.com> | 2023-08-28 12:41:02 +0200 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2023-09-18 18:45:05 +0200 |
commit | 5c54c9ebb1f4758a4da7731a809148ff1a3a1844 (patch) | |
tree | 4811f6f2c29fb757af05bd7deb2bbe064f929978 /lib | |
parent | Linux 6.6-rc2 (diff) | |
download | linux-5c54c9ebb1f4758a4da7731a809148ff1a3a1844.tar.xz linux-5c54c9ebb1f4758a4da7731a809148ff1a3a1844.zip |
kunit: string-stream: Don't create a fragment for empty strings
If the result of the formatted string is an empty string just return
instead of creating an empty fragment.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kunit/string-stream.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c index cc32743c1171..ed24d86af9f5 100644 --- a/lib/kunit/string-stream.c +++ b/lib/kunit/string-stream.c @@ -50,11 +50,17 @@ int string_stream_vadd(struct string_stream *stream, /* Make a copy because `vsnprintf` could change it */ va_copy(args_for_counting, args); - /* Need space for null byte. */ - len = vsnprintf(NULL, 0, fmt, args_for_counting) + 1; + /* Evaluate length of formatted string */ + len = vsnprintf(NULL, 0, fmt, args_for_counting); va_end(args_for_counting); + if (len == 0) + return 0; + + /* Need space for null byte. */ + len++; + frag_container = alloc_string_stream_fragment(stream->test, len, stream->gfp); |