kunit: test: use strlcat in string-stream
Replaces strcat with strlcat to make string-stream's concatenation a
little easier to reason about.
Change-Id: I050da4066b957b6c2d23978c90947e71cf1e8f48
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
diff --git a/test/string-stream.c b/test/string-stream.c
index 396939f97..d77abbe 100644
--- a/test/string-stream.c
+++ b/test/string-stream.c
@@ -77,16 +77,17 @@
static char *string_stream_get_string(struct string_stream *this)
{
struct string_stream_fragment *fragment;
+ size_t buf_len = this->length + 1; /* +1 for null byte. */
char *buf;
unsigned long flags;
- buf = kzalloc(this->length + 1, GFP_KERNEL);
+ buf = kzalloc(buf_len, GFP_KERNEL);
if (!buf)
return NULL;
spin_lock_irqsave(&this->lock, flags);
list_for_each_entry(fragment, &this->fragments, node)
- strcat(buf, fragment->fragment);
+ strlcat(buf, fragment->fragment, buf_len);
spin_unlock_irqrestore(&this->lock, flags);
return buf;
@@ -144,4 +145,4 @@
int string_stream_put(struct string_stream *stream)
{
return kref_put(&stream->refcount, &string_stream_destroy);
-}
\ No newline at end of file
+}