Skip to content

Commit 5c54c9e

Browse files
rfvirgilshuahkh
authored andcommitted
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>
1 parent ce9ecca commit 5c54c9e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/kunit/string-stream.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ int string_stream_vadd(struct string_stream *stream,
5050
/* Make a copy because `vsnprintf` could change it */
5151
va_copy(args_for_counting, args);
5252

53-
/* Need space for null byte. */
54-
len = vsnprintf(NULL, 0, fmt, args_for_counting) + 1;
53+
/* Evaluate length of formatted string */
54+
len = vsnprintf(NULL, 0, fmt, args_for_counting);
5555

5656
va_end(args_for_counting);
5757

58+
if (len == 0)
59+
return 0;
60+
61+
/* Need space for null byte. */
62+
len++;
63+
5864
frag_container = alloc_string_stream_fragment(stream->test,
5965
len,
6066
stream->gfp);

0 commit comments

Comments
 (0)