Fix OCResourceResponseTest warning 85/27485/5
authorMats Wichmann <mats@linux.com>
Fri, 16 Nov 2018 17:13:51 +0000 (10:13 -0700)
committerMats Wichmann <mats@linux.com>
Wed, 30 Jan 2019 17:36:59 +0000 (17:36 +0000)
gcc8.1 is fussier about getting strncpy right, as it gripes on this line:

    strncpy(request.query, query, sizeof(query));

It issues this warning:

resource/unittests/OCResourceResponseTest.cpp:83:39: warning: argument to 'sizeof' in 'char* strncpy(char*, const char*, size_t)' call is the same expression as the source; did you mean to use the size of the destination? [-Wsizeof-pointer-memaccess]

Stack code uses OICStrcpy for safer string copying, but without
fiddling further with dependencies, that function is not available
in this scope, so kept the strncpy but changed the the length
to be based on the destination.

Qualify the two strings with const while we're at it.

Change-Id: I7ed0010a6daeda6f6db4337b9a0babc5e0dce968
Signed-off-by: Mats Wichmann <mats@linux.com>
resource/unittests/OCResourceResponseTest.cpp

index e2678a0..942b60e 100644 (file)
@@ -75,15 +75,16 @@ namespace OCResourceResponseTest
 
     TEST(RequestHandleTest, SetGetRequestHandleValidHandle)
     {
-        char query[] = "?rt=core.light";
-        char address[] = "127.0.0.1";
+        const char query[] = "?rt=core.light";
+        const char address[] = "127.0.0.1";
         OCResourceResponse response;
         OCServerRequest request;
+
         request.method = OC_REST_GET;
-        strncpy(request.query, query, sizeof(query));
+        strncpy(request.query, query, sizeof(request.query));
         request.devAddr.flags = OC_DEFAULT_FLAGS;
         request.devAddr.adapter = OC_DEFAULT_ADAPTER;
-        strncpy(request.devAddr.addr, address, sizeof(query));
+        strncpy(request.devAddr.addr, address, sizeof(request.devAddr.addr));
         request.devAddr.port = 5364;
         request.qos = OC_LOW_QOS;
         request.coapID = 0;