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 <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
09a643ee2c
commit
0515bfff7a
1 changed files with 3 additions and 3 deletions
|
|
@ -109,7 +109,7 @@ static int http_send_data(int sock, char *send_buf,
|
||||||
end_of_send = 0;
|
end_of_send = 0;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
strncpy(send_buf + end_of_send,
|
memcpy(send_buf + end_of_send,
|
||||||
data + end_of_data,
|
data + end_of_data,
|
||||||
remaining_len);
|
remaining_len);
|
||||||
end_of_send += remaining_len;
|
end_of_send += remaining_len;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue