Skip to content

Commit d1b6795

Browse files
maass-hamburgkartben
authored andcommitted
mgmt: hawkbit: move variable declaration out of if
move variable declaration out of if, because it will be optimized away, when optimisation is enabled and leads to undefined and unwanted behavior. In my case `send_buf` of `http_client_req` was put at the same address and the http request was malformed. Signed-off-by: Fin Maaß <[email protected]>
1 parent f5d7081 commit d1b6795

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

subsys/mgmt/hawkbit/hawkbit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,10 @@ static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_r
10991099
static const char *const headers[] = {AUTH_HEADER_FULL, NULL};
11001100
#endif /* CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME */
11011101
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */
1102-
1102+
#ifdef CONFIG_HAWKBIT_SAVE_PROGRESS
1103+
char header_range[RANGE_HEADER_SIZE] = {0};
1104+
char const *headers_range[] = {header_range, NULL};
1105+
#endif
11031106
http_req.url = url_buffer;
11041107
http_req.host = HAWKBIT_SERVER_DOMAIN;
11051108
http_req.port = HAWKBIT_PORT;
@@ -1172,13 +1175,10 @@ static bool send_request(struct hawkbit_context *hb_context, enum hawkbit_http_r
11721175
#ifdef CONFIG_HAWKBIT_SAVE_PROGRESS
11731176
hb_context->dl.downloaded_size = flash_img_bytes_written(&hb_context->flash_ctx);
11741177
if (IN_RANGE(hb_context->dl.downloaded_size, 1, hb_context->dl.file_size)) {
1175-
char header_range[RANGE_HEADER_SIZE] = {0};
1176-
11771178
snprintf(header_range, sizeof(header_range), "Range: bytes=%u-" HTTP_CRLF,
11781179
hb_context->dl.downloaded_size);
1179-
const char *const headers_range[] = {header_range, NULL};
11801180

1181-
http_req.optional_headers = (const char **)headers_range;
1181+
http_req.optional_headers = headers_range;
11821182
LOG_DBG("optional header: %s", header_range);
11831183
LOG_INF("Resuming download from %d bytes", hb_context->dl.downloaded_size);
11841184
}

0 commit comments

Comments
 (0)