projects
/
linux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ce9ecca
)
kunit: string-stream: Don't create a fragment for empty strings
author
Richard Fitzgerald
<rf@opensource.cirrus.com>
Mon, 28 Aug 2023 10:41:02 +0000
(11:41 +0100)
committer
Shuah Khan
<skhan@linuxfoundation.org>
Mon, 18 Sep 2023 16:45:05 +0000
(10:45 -0600)
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>
lib/kunit/string-stream.c
patch
|
blob
|
history
diff --git
a/lib/kunit/string-stream.c
b/lib/kunit/string-stream.c
index cc32743c1171f8eb3e18129d77283733995ae05d..ed24d86af9f5e3b4eece9ee44f3e1d5e78355e4f 100644
(file)
--- 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);