Commit 070c003c authored by Mats Wichmann's avatar Mats Wichmann

Fix OCResourceResponseTest warning

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: default avatarMats Wichmann <>
parent 0aeba4ff
......@@ -75,15 +75,16 @@ namespace OCResourceResponseTest
TEST(RequestHandleTest, SetGetRequestHandleValidHandle)
char query[] = "?rt=core.light";
char address[] = "";
const char query[] = "?rt=core.light";
const char address[] = "";
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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment