Skip to content

Commit 0515bff

Browse files
jukkarmmahadevan108
authored andcommitted
net: lib: http-client: Use memcpy() to avoid gcc warning
GCC 12.2.0 can give this warning (version 11.4.0 did not), when CONFIG_SPEED_OPTIMIZATIONS=y subsys/net/lib/http/http_client.c: In function 'http_send_data.constprop': subsys/net/lib/http/http_client.c:114:33: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation] 114 | strncpy(send_buf + end_of_send, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 115 | data + end_of_data, | ~~~~~~~~~~~~~~~~~~~ 116 | remaining); | ~~~~~~~~~~ subsys/net/lib/http/http_client.c:87:41: note: length computed here 87 | remaining_len = strlen(data + end_of_data); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ The code properly checks that we do not overwrite the destination buffer even if we use the source buffer length to determine how much to copy. One possible fix is to use memcpy() or strcpy(), I opted to use memcpy() because it has the length option which feels more natural. Fixes #79326 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 09a643e commit 0515bff

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

subsys/net/lib/http/http_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ static int http_send_data(int sock, char *send_buf,
109109
end_of_send = 0;
110110
continue;
111111
} else {
112-
strncpy(send_buf + end_of_send,
113-
data + end_of_data,
114-
remaining_len);
112+
memcpy(send_buf + end_of_send,
113+
data + end_of_data,
114+
remaining_len);
115115
end_of_send += remaining_len;
116116
remaining_len = 0;
117117
}

0 commit comments

Comments
 (0)