Skip to content

Commit 3c52a49

Browse files
committed
client: add missing casts
1 parent aabe4bd commit 3c52a49

File tree

9 files changed

+39
-39
lines changed

9 files changed

+39
-39
lines changed

core/src/mender-api.c

100755100644
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ mender_api_perform_authentication(unsigned char *private_key, size_t private_key
130130
/* Format payload */
131131
if (NULL != mender_api_config.tenant_token) {
132132
if (NULL
133-
== (payload = malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\", \"tenant_token\": \"\" }")
134-
+ strlen(mender_api_config.mac_address) + strlen(public_key_pem) + strlen(mender_api_config.tenant_token) + 1))) {
133+
== (payload = (char *)malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\", \"tenant_token\": \"\" }")
134+
+ strlen(mender_api_config.mac_address) + strlen(public_key_pem) + strlen(mender_api_config.tenant_token) + 1))) {
135135
mender_log_error("Unable to allocate memory");
136136
ret = MENDER_FAIL;
137137
goto END;
@@ -143,8 +143,8 @@ mender_api_perform_authentication(unsigned char *private_key, size_t private_key
143143
mender_api_config.tenant_token);
144144
} else {
145145
if (NULL
146-
== (payload = malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\" }") + strlen(mender_api_config.mac_address)
147-
+ strlen(public_key_pem) + 1))) {
146+
== (payload = (char *)malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\" }") + strlen(mender_api_config.mac_address)
147+
+ strlen(public_key_pem) + 1))) {
148148
mender_log_error("Unable to allocate memory");
149149
ret = MENDER_FAIL;
150150
goto END;
@@ -225,8 +225,8 @@ mender_api_check_for_deployment(char **id, char **artifact_name, char **uri) {
225225

226226
/* Compute path */
227227
if (NULL
228-
== (path = malloc(strlen("?artifact_name=&device_type=") + strlen(MENDER_API_PATH_GET_NEXT_DEPLOYMENT) + strlen(mender_api_config.artifact_name)
229-
+ strlen(mender_api_config.device_type) + 1))) {
228+
== (path = (char *)malloc(strlen("?artifact_name=&device_type=") + strlen(MENDER_API_PATH_GET_NEXT_DEPLOYMENT) + strlen(mender_api_config.artifact_name)
229+
+ strlen(mender_api_config.device_type) + 1))) {
230230
mender_log_error("Unable to allocate memory");
231231
ret = MENDER_FAIL;
232232
goto END;
@@ -326,15 +326,15 @@ mender_api_publish_deployment_status(char *id, mender_deployment_status_t deploy
326326
}
327327

328328
/* Format payload */
329-
if (NULL == (payload = malloc(strlen("{ \"status\": \"\" }") + strlen(value) + 1))) {
329+
if (NULL == (payload = (char *)malloc(strlen("{ \"status\": \"\" }") + strlen(value) + 1))) {
330330
mender_log_error("Unable to allocate memory");
331331
ret = MENDER_FAIL;
332332
goto END;
333333
}
334334
sprintf(payload, "{ \"status\": \"%s\" }", value);
335335

336336
/* Compute path */
337-
if (NULL == (path = malloc(strlen(MENDER_API_PATH_PUT_DEPLOYMENT_STATUS) - strlen("%s") + strlen(id) + 1))) {
337+
if (NULL == (path = (char *)malloc(strlen(MENDER_API_PATH_PUT_DEPLOYMENT_STATUS) - strlen("%s") + strlen(id) + 1))) {
338338
mender_log_error("Unable to allocate memory");
339339
ret = MENDER_FAIL;
340340
goto END;

core/src/mender-artifact.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mender_artifact_create_ctx(void) {
126126
mender_artifact_ctx_t *ctx;
127127

128128
/* Create new context */
129-
if (NULL == (ctx = malloc(sizeof(mender_artifact_ctx_t)))) {
129+
if (NULL == (ctx = (mender_artifact_ctx_t *)malloc(sizeof(mender_artifact_ctx_t)))) {
130130
return NULL;
131131
}
132132
memset(ctx, 0, sizeof(mender_artifact_ctx_t));
@@ -307,7 +307,7 @@ mender_artifact_parse_tar_header(mender_artifact_ctx_t *ctx) {
307307

308308
/* Compute the new file name */
309309
if (NULL != ctx->file.name) {
310-
if (NULL == (tmp = malloc(strlen(ctx->file.name) + strlen("/") + strlen(tar_header->name) + 1))) {
310+
if (NULL == (tmp = (char *)malloc(strlen(ctx->file.name) + strlen("/") + strlen(tar_header->name) + 1))) {
311311
mender_log_error("Unable to allocate memory");
312312
return MENDER_FAIL;
313313
}
@@ -648,4 +648,4 @@ mender_artifact_shift_data(mender_artifact_ctx_t *ctx, size_t length) {
648648
static size_t
649649
mender_artifact_round_up(size_t length, size_t incr) {
650650
return length + (incr - length % incr) % incr;
651-
}
651+
}

platform/board/esp-idf/src/mender-storage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ mender_storage_get_authentication_keys(unsigned char **private_key, size_t *priv
9292
}
9393

9494
/* Allocate memory to copy keys */
95-
if (NULL == (*private_key = malloc(*private_key_length))) {
95+
if (NULL == (*private_key = (unsigned char *)malloc(*private_key_length))) {
9696
mender_log_error("Unable to allocate memory");
9797
return MENDER_FAIL;
9898
}
99-
if (NULL == (*public_key = malloc(*public_key_length))) {
99+
if (NULL == (*public_key = (unsigned char *)malloc(*public_key_length))) {
100100
mender_log_error("Unable to allocate memory");
101101
free(*private_key);
102102
*private_key = NULL;
@@ -171,11 +171,11 @@ mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
171171
}
172172

173173
/* Allocate memory to copy ID and artifact name */
174-
if (NULL == (*ota_id = malloc(ota_id_length + 1))) {
174+
if (NULL == (*ota_id = (char *)malloc(ota_id_length + 1))) {
175175
mender_log_error("Unable to allocate memory");
176176
return MENDER_FAIL;
177177
}
178-
if (NULL == (*ota_artifact_name = malloc(ota_artifact_name_length + 1))) {
178+
if (NULL == (*ota_artifact_name = (char *)malloc(ota_artifact_name_length + 1))) {
179179
mender_log_error("Unable to allocate memory");
180180
free(*ota_id);
181181
*ota_id = NULL;
@@ -244,7 +244,7 @@ mender_storage_get_device_config(char **device_config) {
244244
}
245245

246246
/* Allocate memory to copy device configuration */
247-
if (NULL == (*device_config = malloc(device_config_length + 1))) {
247+
if (NULL == (*device_config = (char *)malloc(device_config_length + 1))) {
248248
mender_log_error("Unable to allocate memory");
249249
return MENDER_FAIL;
250250
}

platform/board/zephyr/src/mender-storage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ mender_storage_get_authentication_keys(unsigned char **private_key, size_t *priv
119119
*public_key_length = (size_t)ret;
120120

121121
/* Allocate memory to copy keys */
122-
if (NULL == (*private_key = malloc(*private_key_length))) {
122+
if (NULL == (*private_key = (unsigned char *)malloc(*private_key_length))) {
123123
mender_log_error("Unable to allocate memory");
124124
return MENDER_FAIL;
125125
}
126-
if (NULL == (*public_key = malloc(*public_key_length))) {
126+
if (NULL == (*public_key = (unsigned char *)malloc(*public_key_length))) {
127127
mender_log_error("Unable to allocate memory");
128128
free(*private_key);
129129
*private_key = NULL;
@@ -195,11 +195,11 @@ mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
195195
ota_artifact_name_length = (size_t)ret;
196196

197197
/* Allocate memory to copy ID and artifact name */
198-
if (NULL == (*ota_id = malloc(ota_id_length))) {
198+
if (NULL == (*ota_id = (char *)malloc(ota_id_length))) {
199199
mender_log_error("Unable to allocate memory");
200200
return MENDER_FAIL;
201201
}
202-
if (NULL == (*ota_artifact_name = malloc(ota_artifact_name_length))) {
202+
if (NULL == (*ota_artifact_name = (char *)malloc(ota_artifact_name_length))) {
203203
mender_log_error("Unable to allocate memory");
204204
free(*ota_id);
205205
*ota_id = NULL;
@@ -265,7 +265,7 @@ mender_storage_get_device_config(char **device_config) {
265265
device_config_length = (size_t)ret;
266266

267267
/* Allocate memory to copy device configuration */
268-
if (NULL == (*device_config = malloc(device_config_length))) {
268+
if (NULL == (*device_config = (char *)malloc(device_config_length))) {
269269
mender_log_error("Unable to allocate memory");
270270
return MENDER_FAIL;
271271
}

platform/http/esp-idf/src/mender-http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ mender_http_perform(char * jwt,
7676

7777
/* Compute URL if required */
7878
if (strncmp(path, "http", strlen("http"))) {
79-
if (NULL == (url = malloc(strlen(mender_http_config.host) + strlen(path) + 1))) {
79+
if (NULL == (url = (char *)malloc(strlen(mender_http_config.host) + strlen(path) + 1))) {
8080
mender_log_error("Unable to allocate memory");
8181
ret = MENDER_FAIL;
8282
goto END;
@@ -95,7 +95,7 @@ mender_http_perform(char * jwt,
9595
}
9696
esp_http_client_set_method(client, mender_http_method_to_esp_http_client_method(method));
9797
if (NULL != jwt) {
98-
if (NULL == (bearer = malloc(strlen("Bearer ") + strlen(jwt) + 1))) {
98+
if (NULL == (bearer = (char *)malloc(strlen("Bearer ") + strlen(jwt) + 1))) {
9999
mender_log_error("Unable to allocate memory");
100100
ret = MENDER_FAIL;
101101
goto END;

platform/http/zephyr/src/mender-http.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mender_http_perform(char * jwt,
167167
}
168168
request.recv_buf_len = MENDER_HTTP_RECV_BUF_LENGTH;
169169
if (NULL != jwt) {
170-
if (NULL == (header_fields[header_index] = malloc(strlen("Authorization: Bearer ") + strlen(jwt) + strlen("\r\n") + 1))) {
170+
if (NULL == (header_fields[header_index] = (char *)malloc(strlen("Authorization: Bearer ") + strlen(jwt) + strlen("\r\n") + 1))) {
171171
mender_log_error("Unable to allocate memory");
172172
ret = MENDER_FAIL;
173173
goto END;
@@ -176,7 +176,7 @@ mender_http_perform(char * jwt,
176176
header_index++;
177177
}
178178
if (NULL != signature) {
179-
if (NULL == (header_fields[header_index] = malloc(strlen("X-MEN-Signature: ") + strlen(signature) + strlen("\r\n") + 1))) {
179+
if (NULL == (header_fields[header_index] = (char *)malloc(strlen("X-MEN-Signature: ") + strlen(signature) + strlen("\r\n") + 1))) {
180180
mender_log_error("Unable to allocate memory");
181181
ret = MENDER_FAIL;
182182
goto END;
@@ -431,7 +431,7 @@ mender_http_get_host_port_url(char *path, char **host, char **port, char **url)
431431
char *pch2 = strchr(pch1, ':');
432432
if (NULL != pch2) {
433433
/* Port is specified */
434-
if (NULL == (*host = malloc(pch2 - pch1 + 1))) {
434+
if (NULL == (*host = (char *)malloc(pch2 - pch1 + 1))) {
435435
mender_log_error("Unable to allocate memory");
436436
free(tmp);
437437
return MENDER_FAIL;

platform/rtos/freertos/src/mender-rtos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mender_rtos_work_create(mender_rtos_work_params_t *work_params, void **handle) {
117117
assert(NULL != handle);
118118

119119
/* Create work context */
120-
mender_rtos_work_context_t *work_context = malloc(sizeof(mender_rtos_work_context_t));
120+
mender_rtos_work_context_t *work_context = (mender_rtos_work_context_t *)malloc(sizeof(mender_rtos_work_context_t));
121121
if (NULL == work_context) {
122122
mender_log_error("Unable to allocate memory");
123123
goto FAIL;

platform/rtos/zephyr/src/mender-rtos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mender_rtos_work_create(mender_rtos_work_params_t *work_params, void **handle) {
9898
assert(NULL != handle);
9999

100100
/* Create work context */
101-
mender_rtos_work_context_t *work_context = malloc(sizeof(mender_rtos_work_context_t));
101+
mender_rtos_work_context_t *work_context = (mender_rtos_work_context_t *)malloc(sizeof(mender_rtos_work_context_t));
102102
if (NULL == work_context) {
103103
mender_log_error("Unable to allocate memory");
104104
goto FAIL;

platform/tls/mbedtls/src/mender-tls.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
8080
#endif /* MBEDTLS_ERROR_C */
8181

8282
/* Initialize mbedtls */
83-
if (NULL == (pk_context = malloc(sizeof(mbedtls_pk_context)))) {
83+
if (NULL == (pk_context = (mbedtls_pk_context *)malloc(sizeof(mbedtls_pk_context)))) {
8484
mender_log_error("Unable to allocate memory");
8585
ret = -1;
8686
goto END;
8787
}
8888
mbedtls_pk_init(pk_context);
89-
if (NULL == (ctr_drbg = malloc(sizeof(mbedtls_ctr_drbg_context)))) {
89+
if (NULL == (ctr_drbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)))) {
9090
mender_log_error("Unable to allocate memory");
9191
ret = -1;
9292
goto END;
9393
}
9494
mbedtls_ctr_drbg_init(ctr_drbg);
95-
if (NULL == (entropy = malloc(sizeof(mbedtls_entropy_context)))) {
95+
if (NULL == (entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)))) {
9696
mender_log_error("Unable to allocate memory");
9797
ret = -1;
9898
goto END;
@@ -133,7 +133,7 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
133133
}
134134

135135
/* Export private key */
136-
if (NULL == (*private_key = malloc(MENDER_TLS_PRIVATE_KEY_LENGTH))) {
136+
if (NULL == (*private_key = (unsigned char *)malloc(MENDER_TLS_PRIVATE_KEY_LENGTH))) {
137137
mender_log_error("Unable to allocate memory");
138138
ret = -1;
139139
goto END;
@@ -161,7 +161,7 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
161161
*private_key = tmp;
162162

163163
/* Export public key */
164-
if (NULL == (*public_key = malloc(MENDER_TLS_PUBLIC_KEY_LENGTH))) {
164+
if (NULL == (*public_key = (unsigned char *)malloc(MENDER_TLS_PUBLIC_KEY_LENGTH))) {
165165
mender_log_error("Unable to allocate memory");
166166
free(*private_key);
167167
*private_key = NULL;
@@ -243,7 +243,7 @@ mender_tls_pem_write_buffer(const unsigned char *der_data, size_t der_len, char
243243
}
244244

245245
/* Allocate memory to store PEM data */
246-
if (NULL == (encode_buf = malloc(use_len))) {
246+
if (NULL == (encode_buf = (unsigned char *)malloc(use_len))) {
247247
ret = MENDER_FAIL;
248248
goto END;
249249
}
@@ -312,19 +312,19 @@ mender_tls_sign_payload(unsigned char *private_key, size_t private_key_length, c
312312
#endif /* MBEDTLS_ERROR_C */
313313

314314
/* Initialize mbedtls */
315-
if (NULL == (pk_context = malloc(sizeof(mbedtls_pk_context)))) {
315+
if (NULL == (pk_context = (mbedtls_pk_context *)malloc(sizeof(mbedtls_pk_context)))) {
316316
mender_log_error("Unable to allocate memory");
317317
ret = -1;
318318
goto END;
319319
}
320320
mbedtls_pk_init(pk_context);
321-
if (NULL == (ctr_drbg = malloc(sizeof(mbedtls_ctr_drbg_context)))) {
321+
if (NULL == (ctr_drbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)))) {
322322
mender_log_error("Unable to allocate memory");
323323
ret = -1;
324324
goto END;
325325
}
326326
mbedtls_ctr_drbg_init(ctr_drbg);
327-
if (NULL == (entropy = malloc(sizeof(mbedtls_entropy_context)))) {
327+
if (NULL == (entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)))) {
328328
mender_log_error("Unable to allocate memory");
329329
ret = -1;
330330
goto END;
@@ -370,7 +370,7 @@ mender_tls_sign_payload(unsigned char *private_key, size_t private_key_length, c
370370
}
371371

372372
/* Compute signature */
373-
if (NULL == (sig = malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
373+
if (NULL == (sig = (unsigned char *)malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
374374
mender_log_error("Unable to allocate memory");
375375
ret = -1;
376376
goto END;
@@ -391,7 +391,7 @@ mender_tls_sign_payload(unsigned char *private_key, size_t private_key_length, c
391391
}
392392

393393
/* Encode signature to base64 */
394-
if (NULL == (*signature = malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
394+
if (NULL == (*signature = (char *)malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
395395
mender_log_error("Unable to allocate memory");
396396
ret = -1;
397397
goto END;

0 commit comments

Comments
 (0)