Commit 5c54c9eb authored by Richard Fitzgerald's avatar Richard Fitzgerald Committed by Shuah Khan

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: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: default avatarRae Moar <rmoar@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent ce9ecca0
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment