Skip to content

Commit

Permalink
client: add missing casts
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed Jun 20, 2023
1 parent aabe4bd commit 3c52a49
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions core/src/mender-api.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ mender_api_perform_authentication(unsigned char *private_key, size_t private_key
/* Format payload */
if (NULL != mender_api_config.tenant_token) {
if (NULL
== (payload = malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\", \"tenant_token\": \"\" }")
+ strlen(mender_api_config.mac_address) + strlen(public_key_pem) + strlen(mender_api_config.tenant_token) + 1))) {
== (payload = (char *)malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\", \"tenant_token\": \"\" }")
+ strlen(mender_api_config.mac_address) + strlen(public_key_pem) + strlen(mender_api_config.tenant_token) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand All @@ -143,8 +143,8 @@ mender_api_perform_authentication(unsigned char *private_key, size_t private_key
mender_api_config.tenant_token);
} else {
if (NULL
== (payload = malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\" }") + strlen(mender_api_config.mac_address)
+ strlen(public_key_pem) + 1))) {
== (payload = (char *)malloc(strlen("{ \"id_data\": \"{ \\\"mac\\\": \\\"\\\"}\", \"pubkey\": \"\" }") + strlen(mender_api_config.mac_address)
+ strlen(public_key_pem) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand Down Expand Up @@ -225,8 +225,8 @@ mender_api_check_for_deployment(char **id, char **artifact_name, char **uri) {

/* Compute path */
if (NULL
== (path = malloc(strlen("?artifact_name=&device_type=") + strlen(MENDER_API_PATH_GET_NEXT_DEPLOYMENT) + strlen(mender_api_config.artifact_name)
+ strlen(mender_api_config.device_type) + 1))) {
== (path = (char *)malloc(strlen("?artifact_name=&device_type=") + strlen(MENDER_API_PATH_GET_NEXT_DEPLOYMENT) + strlen(mender_api_config.artifact_name)
+ strlen(mender_api_config.device_type) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand Down Expand Up @@ -326,15 +326,15 @@ mender_api_publish_deployment_status(char *id, mender_deployment_status_t deploy
}

/* Format payload */
if (NULL == (payload = malloc(strlen("{ \"status\": \"\" }") + strlen(value) + 1))) {
if (NULL == (payload = (char *)malloc(strlen("{ \"status\": \"\" }") + strlen(value) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
}
sprintf(payload, "{ \"status\": \"%s\" }", value);

/* Compute path */
if (NULL == (path = malloc(strlen(MENDER_API_PATH_PUT_DEPLOYMENT_STATUS) - strlen("%s") + strlen(id) + 1))) {
if (NULL == (path = (char *)malloc(strlen(MENDER_API_PATH_PUT_DEPLOYMENT_STATUS) - strlen("%s") + strlen(id) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand Down
6 changes: 3 additions & 3 deletions core/src/mender-artifact.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mender_artifact_create_ctx(void) {
mender_artifact_ctx_t *ctx;

/* Create new context */
if (NULL == (ctx = malloc(sizeof(mender_artifact_ctx_t)))) {
if (NULL == (ctx = (mender_artifact_ctx_t *)malloc(sizeof(mender_artifact_ctx_t)))) {
return NULL;
}
memset(ctx, 0, sizeof(mender_artifact_ctx_t));
Expand Down Expand Up @@ -307,7 +307,7 @@ mender_artifact_parse_tar_header(mender_artifact_ctx_t *ctx) {

/* Compute the new file name */
if (NULL != ctx->file.name) {
if (NULL == (tmp = malloc(strlen(ctx->file.name) + strlen("/") + strlen(tar_header->name) + 1))) {
if (NULL == (tmp = (char *)malloc(strlen(ctx->file.name) + strlen("/") + strlen(tar_header->name) + 1))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
Expand Down Expand Up @@ -648,4 +648,4 @@ mender_artifact_shift_data(mender_artifact_ctx_t *ctx, size_t length) {
static size_t
mender_artifact_round_up(size_t length, size_t incr) {
return length + (incr - length % incr) % incr;
}
}
10 changes: 5 additions & 5 deletions platform/board/esp-idf/src/mender-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ mender_storage_get_authentication_keys(unsigned char **private_key, size_t *priv
}

/* Allocate memory to copy keys */
if (NULL == (*private_key = malloc(*private_key_length))) {
if (NULL == (*private_key = (unsigned char *)malloc(*private_key_length))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
if (NULL == (*public_key = malloc(*public_key_length))) {
if (NULL == (*public_key = (unsigned char *)malloc(*public_key_length))) {
mender_log_error("Unable to allocate memory");
free(*private_key);
*private_key = NULL;
Expand Down Expand Up @@ -171,11 +171,11 @@ mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
}

/* Allocate memory to copy ID and artifact name */
if (NULL == (*ota_id = malloc(ota_id_length + 1))) {
if (NULL == (*ota_id = (char *)malloc(ota_id_length + 1))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
if (NULL == (*ota_artifact_name = malloc(ota_artifact_name_length + 1))) {
if (NULL == (*ota_artifact_name = (char *)malloc(ota_artifact_name_length + 1))) {
mender_log_error("Unable to allocate memory");
free(*ota_id);
*ota_id = NULL;
Expand Down Expand Up @@ -244,7 +244,7 @@ mender_storage_get_device_config(char **device_config) {
}

/* Allocate memory to copy device configuration */
if (NULL == (*device_config = malloc(device_config_length + 1))) {
if (NULL == (*device_config = (char *)malloc(device_config_length + 1))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
Expand Down
10 changes: 5 additions & 5 deletions platform/board/zephyr/src/mender-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ mender_storage_get_authentication_keys(unsigned char **private_key, size_t *priv
*public_key_length = (size_t)ret;

/* Allocate memory to copy keys */
if (NULL == (*private_key = malloc(*private_key_length))) {
if (NULL == (*private_key = (unsigned char *)malloc(*private_key_length))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
if (NULL == (*public_key = malloc(*public_key_length))) {
if (NULL == (*public_key = (unsigned char *)malloc(*public_key_length))) {
mender_log_error("Unable to allocate memory");
free(*private_key);
*private_key = NULL;
Expand Down Expand Up @@ -195,11 +195,11 @@ mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
ota_artifact_name_length = (size_t)ret;

/* Allocate memory to copy ID and artifact name */
if (NULL == (*ota_id = malloc(ota_id_length))) {
if (NULL == (*ota_id = (char *)malloc(ota_id_length))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
if (NULL == (*ota_artifact_name = malloc(ota_artifact_name_length))) {
if (NULL == (*ota_artifact_name = (char *)malloc(ota_artifact_name_length))) {
mender_log_error("Unable to allocate memory");
free(*ota_id);
*ota_id = NULL;
Expand Down Expand Up @@ -265,7 +265,7 @@ mender_storage_get_device_config(char **device_config) {
device_config_length = (size_t)ret;

/* Allocate memory to copy device configuration */
if (NULL == (*device_config = malloc(device_config_length))) {
if (NULL == (*device_config = (char *)malloc(device_config_length))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
Expand Down
4 changes: 2 additions & 2 deletions platform/http/esp-idf/src/mender-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mender_http_perform(char * jwt,

/* Compute URL if required */
if (strncmp(path, "http", strlen("http"))) {
if (NULL == (url = malloc(strlen(mender_http_config.host) + strlen(path) + 1))) {
if (NULL == (url = (char *)malloc(strlen(mender_http_config.host) + strlen(path) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand All @@ -95,7 +95,7 @@ mender_http_perform(char * jwt,
}
esp_http_client_set_method(client, mender_http_method_to_esp_http_client_method(method));
if (NULL != jwt) {
if (NULL == (bearer = malloc(strlen("Bearer ") + strlen(jwt) + 1))) {
if (NULL == (bearer = (char *)malloc(strlen("Bearer ") + strlen(jwt) + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand Down
6 changes: 3 additions & 3 deletions platform/http/zephyr/src/mender-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mender_http_perform(char * jwt,
}
request.recv_buf_len = MENDER_HTTP_RECV_BUF_LENGTH;
if (NULL != jwt) {
if (NULL == (header_fields[header_index] = malloc(strlen("Authorization: Bearer ") + strlen(jwt) + strlen("\r\n") + 1))) {
if (NULL == (header_fields[header_index] = (char *)malloc(strlen("Authorization: Bearer ") + strlen(jwt) + strlen("\r\n") + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand All @@ -176,7 +176,7 @@ mender_http_perform(char * jwt,
header_index++;
}
if (NULL != signature) {
if (NULL == (header_fields[header_index] = malloc(strlen("X-MEN-Signature: ") + strlen(signature) + strlen("\r\n") + 1))) {
if (NULL == (header_fields[header_index] = (char *)malloc(strlen("X-MEN-Signature: ") + strlen(signature) + strlen("\r\n") + 1))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
Expand Down Expand Up @@ -431,7 +431,7 @@ mender_http_get_host_port_url(char *path, char **host, char **port, char **url)
char *pch2 = strchr(pch1, ':');
if (NULL != pch2) {
/* Port is specified */
if (NULL == (*host = malloc(pch2 - pch1 + 1))) {
if (NULL == (*host = (char *)malloc(pch2 - pch1 + 1))) {
mender_log_error("Unable to allocate memory");
free(tmp);
return MENDER_FAIL;
Expand Down
2 changes: 1 addition & 1 deletion platform/rtos/freertos/src/mender-rtos.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mender_rtos_work_create(mender_rtos_work_params_t *work_params, void **handle) {
assert(NULL != handle);

/* Create work context */
mender_rtos_work_context_t *work_context = malloc(sizeof(mender_rtos_work_context_t));
mender_rtos_work_context_t *work_context = (mender_rtos_work_context_t *)malloc(sizeof(mender_rtos_work_context_t));
if (NULL == work_context) {
mender_log_error("Unable to allocate memory");
goto FAIL;
Expand Down
2 changes: 1 addition & 1 deletion platform/rtos/zephyr/src/mender-rtos.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mender_rtos_work_create(mender_rtos_work_params_t *work_params, void **handle) {
assert(NULL != handle);

/* Create work context */
mender_rtos_work_context_t *work_context = malloc(sizeof(mender_rtos_work_context_t));
mender_rtos_work_context_t *work_context = (mender_rtos_work_context_t *)malloc(sizeof(mender_rtos_work_context_t));
if (NULL == work_context) {
mender_log_error("Unable to allocate memory");
goto FAIL;
Expand Down
22 changes: 11 additions & 11 deletions platform/tls/mbedtls/src/mender-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
#endif /* MBEDTLS_ERROR_C */

/* Initialize mbedtls */
if (NULL == (pk_context = malloc(sizeof(mbedtls_pk_context)))) {
if (NULL == (pk_context = (mbedtls_pk_context *)malloc(sizeof(mbedtls_pk_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
}
mbedtls_pk_init(pk_context);
if (NULL == (ctr_drbg = malloc(sizeof(mbedtls_ctr_drbg_context)))) {
if (NULL == (ctr_drbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
}
mbedtls_ctr_drbg_init(ctr_drbg);
if (NULL == (entropy = malloc(sizeof(mbedtls_entropy_context)))) {
if (NULL == (entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
Expand Down Expand Up @@ -133,7 +133,7 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
}

/* Export private key */
if (NULL == (*private_key = malloc(MENDER_TLS_PRIVATE_KEY_LENGTH))) {
if (NULL == (*private_key = (unsigned char *)malloc(MENDER_TLS_PRIVATE_KEY_LENGTH))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
Expand Down Expand Up @@ -161,7 +161,7 @@ mender_tls_generate_authentication_keys(unsigned char **private_key, size_t *pri
*private_key = tmp;

/* Export public key */
if (NULL == (*public_key = malloc(MENDER_TLS_PUBLIC_KEY_LENGTH))) {
if (NULL == (*public_key = (unsigned char *)malloc(MENDER_TLS_PUBLIC_KEY_LENGTH))) {
mender_log_error("Unable to allocate memory");
free(*private_key);
*private_key = NULL;
Expand Down Expand Up @@ -243,7 +243,7 @@ mender_tls_pem_write_buffer(const unsigned char *der_data, size_t der_len, char
}

/* Allocate memory to store PEM data */
if (NULL == (encode_buf = malloc(use_len))) {
if (NULL == (encode_buf = (unsigned char *)malloc(use_len))) {
ret = MENDER_FAIL;
goto END;
}
Expand Down Expand Up @@ -312,19 +312,19 @@ mender_tls_sign_payload(unsigned char *private_key, size_t private_key_length, c
#endif /* MBEDTLS_ERROR_C */

/* Initialize mbedtls */
if (NULL == (pk_context = malloc(sizeof(mbedtls_pk_context)))) {
if (NULL == (pk_context = (mbedtls_pk_context *)malloc(sizeof(mbedtls_pk_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
}
mbedtls_pk_init(pk_context);
if (NULL == (ctr_drbg = malloc(sizeof(mbedtls_ctr_drbg_context)))) {
if (NULL == (ctr_drbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
}
mbedtls_ctr_drbg_init(ctr_drbg);
if (NULL == (entropy = malloc(sizeof(mbedtls_entropy_context)))) {
if (NULL == (entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
Expand Down Expand Up @@ -370,7 +370,7 @@ mender_tls_sign_payload(unsigned char *private_key, size_t private_key_length, c
}

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

/* Encode signature to base64 */
if (NULL == (*signature = malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
if (NULL == (*signature = (char *)malloc(MENDER_TLS_SIGNATURE_LENGTH + 1))) {
mender_log_error("Unable to allocate memory");
ret = -1;
goto END;
Expand Down

0 comments on commit 3c52a49

Please sign in to comment.