unit: Fix Clang 8 "-Wstring-plus-int" warning
PATCH 1/1 unit: Fix Clang 8 "-Wstring-plus-int" warning
Declare the fixed string in unit/test-checksum.c as a static array instead of a string literal to address a warning exhibited by Clang 8 regarding addition of an integer to a string:
unit/test-checksum.c:170:30: warning: adding 'unsigned long' to a
string does not append to the string [-Wstring-plus-int]
iov[1].iov_base = FIXED_STR + FIXED_LEN / 2;
~~~~~~~~~~^~~~~~~~~~~~~~~
unit/test-checksum.c:170:30: note: use array indexing to silence this
warning
iov[1].iov_base = FIXED_STR + FIXED_LEN / 2;
^
& [ ]Storing the string in an array makes it obvious that pointer arithmetic is being performed.
--- unit/test-checksum.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
unit/test-checksum.c +6 -4
@@ -28,10 +28,12 @@#include <ell/ell.h> -#define FIXED_STR "The quick brown fox jumps over the lazy dog. " \ - "Jackdaws love my big sphinx of quartz. " \ - "Pack my box with five dozen liquor jugs. " \ - "How razorback-jumping frogs can level six piqued gymnasts!" +static char FIXED_STR [] = +"The quick brown fox jumps over the lazy dog. " +"Jackdaws love my big sphinx of quartz. " +"Pack my box with five dozen liquor jugs. " +"How razorback-jumping frogs can level six piqued gymnasts!" ; +#define FIXED_LEN (strlen (FIXED_STR))static void test_unsupported (const void *data)
Signature · 1 line
2.20.1
Denis Kenzior
AppliedHi Ossama,
Quoted 14 lines · Ossama Othman
Declare the fixed string in
unit/test-checksum.cas a static array instead of a string literal to address a warning exhibited by Clang 8 regarding addition of an integer to a string:
unit/test-checksum.c:170:30: warning: adding 'unsigned long' to astring does not append to the string [-Wstring-plus-int] iov[1].iov_base = FIXED_STR + FIXED_LEN / 2; ~~~~~~~~~~^~~~~~~~~~~~~~~ unit/test-checksum.c:170:30: note: use array indexing to silence this warning iov[1].iov_base = FIXED_STR + FIXED_LEN / 2; ^ & [ ]
Quoted 6 lines
Storing the string in an array makes it obvious that pointer arithmetic is being performed.
--- unit/test-checksum.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Applied, thanks.
Regards,
-Denis