util/string_buffer: fix warning in tests
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 16 Jul 2018 22:12:00 +0000 (15:12 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 18 Jul 2018 15:29:51 +0000 (08:29 -0700)
commit3bf19bfdc618aabca8e2095e8f2ba4f533aa0bfc
treebc4a883c540a125d7601b12b874def9a5c778fc5
parent577c8d72882a909ae7d2c90d7c8250c77475f9a4
util/string_buffer: fix warning in tests

And also specify the maximum size when writing to static buffers. The
warning below refers to the case where "str5" could be larger than
"str5 - str4", then the strcat would have overlapping dst and src.

Compiler doesn't pick up the bound from the snprintf above, so we make
clear the bounds of str5 by using strncat() instead of strcat().

../../src/util/tests/string_buffer/string_buffer_test.cpp: In member function ‘virtual void string_buffer_string_buffer_tests_Test::TestBody()’:
../../src/util/tests/string_buffer/string_buffer_test.cpp:106:10: warning: ‘char* strcat(char*, const char*)’ accessing 81 or more bytes at offsets 48 and 128 may overlap 1 byte at offset 128 [-Wrestrict]
    strcat(str4, str5);
    ~~~~~~^~~~~~~~~~~~

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
src/util/tests/string_buffer/string_buffer_test.cpp