Commit 34cb4415 authored by Kishen Maloor's avatar Kishen Maloor

Fix build warnings and errors on Windows

Change-Id: I7a20ab73cea3569655a74d3edd007a710a989846
Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/27907Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
parent 73427767
......@@ -176,7 +176,7 @@ _oc_copy_byte_string_to_array(oc_string_array_t *ocstringarray,
return false;
}
size_t pos = index * STRING_ARRAY_ITEM_MAX_LEN;
oc_string(*ocstringarray)[pos] = str_len;
oc_string(*ocstringarray)[pos] = (uint8_t)str_len;
pos++;
memcpy(oc_string(*ocstringarray) + pos, (const uint8_t *)str, str_len);
return true;
......
......@@ -277,7 +277,7 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
uint8_t *size =
(uint8_t *)oc_byte_string_array_get_item(cur->value.array, k);
size -= 1;
*size = len;
*size = (uint8_t)len;
*err |= cbor_value_copy_byte_string(
&array, (uint8_t *)oc_byte_string_array_get_item(cur->value.array, k),
&len, NULL);
......
......@@ -1198,7 +1198,7 @@ done:
static int
connectivity_ipv4_init(ip_context_t *dev)
{
OC_DBG("Initializing IPv4 connectivity for device %d", dev->device);
OC_DBG("Initializing IPv4 connectivity for device %zd", dev->device);
memset(&dev->mcast4, 0, sizeof(dev->mcast4));
memset(&dev->server4, 0, sizeof(dev->server4));
......@@ -1308,7 +1308,7 @@ connectivity_ipv4_init(ip_context_t *dev)
dev->dtls4_port = ntohs(sm->sin_port);
#endif /* OC_SECURITY */
OC_DBG("Successfully initialized IPv4 connectivity for device %d",
OC_DBG("Successfully initialized IPv4 connectivity for device %zd",
dev->device);
return 0;
......@@ -1323,7 +1323,7 @@ oc_connectivity_init(size_t device)
WSAStartup(MAKEWORD(2, 2), &wsadata);
}
OC_DBG("Initializing connectivity for device %d", device);
OC_DBG("Initializing connectivity for device %zd", device);
#ifdef OC_DYNAMIC_ALLOCATION
ip_context_t *dev = (ip_context_t *)calloc(1, sizeof(ip_context_t));
if (!dev) {
......@@ -1501,7 +1501,7 @@ oc_connectivity_init(size_t device)
return -1;
}
OC_DBG("Successfully initialized connectivity for device %d", device);
OC_DBG("Successfully initialized connectivity for device %zd", device);
return 0;
}
......@@ -1539,5 +1539,5 @@ oc_connectivity_shutdown(size_t device)
free(dev);
#endif /* OC_DYNAMIC_ALLOCATION */
OC_DBG("oc_connectivity_shutdown for device %d", device);
OC_DBG("oc_connectivity_shutdown for device %zd", device);
}
......@@ -283,7 +283,7 @@ oc_certs_serialize_to_pem(const mbedtls_x509_crt *cert, char *output_buffer,
j += strlen(end);
output_buffer[j] = '\0';
return j;
return (int)j;
}
int
......@@ -301,7 +301,7 @@ oc_certs_serialize_chain_to_pem(const mbedtls_x509_crt *cert_chain,
buffer_len -= strlen(output_buffer);
cert = cert->next;
}
return strlen(output_buffer);
return (int)strlen(output_buffer);
}
static int
......@@ -647,13 +647,13 @@ oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len)
{
oc_ecdsa_keypair_t *kp = oc_sec_get_ecdsa_keypair(device);
if (!kp) {
OC_ERR("could not find public/private key pair on device %d", device);
OC_ERR("could not find public/private key pair on device %zd", device);
return -1;
}
oc_uuid_t *uuid = oc_core_get_device_id(device);
if (!uuid) {
OC_ERR("could not obtain UUID for device %d", device);
OC_ERR("could not obtain UUID for device %zd", device);
return -1;
}
......@@ -673,13 +673,13 @@ oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len)
int ret =
mbedtls_pk_parse_public_key(&pk, kp->public_key, OC_KEYPAIR_PUBKEY_SIZE);
if (ret != 0) {
OC_ERR("could not parse public key for device %d", device);
OC_ERR("could not parse public key for device %zd", device);
goto generate_csr_error;
}
ret = mbedtls_pk_parse_key(&pk, kp->private_key, kp->private_key_size, 0, 0);
if (ret != 0) {
OC_ERR("could not parse private key for device %d", device);
OC_ERR("could not parse private key for device %zd", device);
goto generate_csr_error;
}
......@@ -704,7 +704,7 @@ oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len)
ret = mbedtls_x509write_csr_set_subject_name(&request, subject);
if (ret != 0) {
OC_ERR("could not write subject name into CSR for device %d", device);
OC_ERR("could not write subject name into CSR for device %zd", device);
goto generate_csr_error;
}
......@@ -714,7 +714,7 @@ oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len)
mbedtls_ctr_drbg_random, &ctr_drbg);
if (ret <= 0) {
OC_ERR("could not write CSR for device %d into buffer", device);
OC_ERR("could not write CSR for device %zd into buffer", device);
goto generate_csr_error;
}
memmove(csr, csr + csr_len - ret, ret);
......@@ -724,7 +724,7 @@ oc_certs_generate_csr(size_t device, unsigned char *csr, size_t csr_len)
mbedtls_entropy_free(&entropy);
mbedtls_x509write_csr_free(&request);
OC_DBG("successfully generated CSR for device %d", device);
OC_DBG("successfully generated CSR for device %zd", device);
return ret;
......
......@@ -30,10 +30,23 @@ get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
size_t device = request->resource->device;
#ifdef OC_DYNAMIC_ALLOCATION
unsigned char *csr =
(unsigned char *)calloc(OC_PDU_SIZE, sizeof(unsigned char));
if (!csr) {
oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR);
return;
}
#else /* OC_DYNAMIC_ALLOCATION */
unsigned char csr[OC_PDU_SIZE];
#endif /* !OC_DYNAMIC_ALLOCATION */
int csr_len = oc_certs_generate_csr(device, csr, OC_PDU_SIZE);
if (csr_len < 0) {
oc_send_response(request, OC_STATUS_INTERNAL_SERVER_ERROR);
#ifdef OC_DYNAMIC_ALLOCATION
free(csr);
#endif /* OC_DYNAMIC_ALLOCATION */
return;
}
......@@ -45,6 +58,10 @@ get_csr(oc_request_t *request, oc_interface_mask_t iface_mask, void *data)
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
#ifdef OC_DYNAMIC_ALLOCATION
free(csr);
#endif /* OC_DYNAMIC_ALLOCATION */
}
#else /* OC_PKI */
......
......@@ -89,7 +89,7 @@ oc_sec_decode_ecdsa_keypair(oc_rep_t *rep, size_t device)
}
memcpy(kp->private_key, oc_cast(rep->value.string, uint8_t),
oc_string_len(rep->value.string));
kp->private_key_size = oc_string_len(rep->value.string);
kp->private_key_size = (uint8_t)oc_string_len(rep->value.string);
}
}
rep = rep->next;
......@@ -166,7 +166,7 @@ oc_generate_ecdsa_keypair(size_t device)
OC_ERR("error writing EC private key to internal structure");
goto generate_ecdsa_keypair_error;
}
kp->private_key_size = ret;
kp->private_key_size = (uint8_t)ret;
memmove(kp->private_key, kp->private_key + OC_KEYPAIR_PRIVKEY_SIZE - ret,
kp->private_key_size);
......@@ -177,7 +177,7 @@ oc_generate_ecdsa_keypair(size_t device)
goto generate_ecdsa_keypair_error;
}
OC_DBG("successfully generated ECDSA keypair for device %d", device);
OC_DBG("successfully generated ECDSA keypair for device %zd", device);
mbedtls_entropy_free(&entropy);
mbedtls_ctr_drbg_free(&ctr_drbg);
......
......@@ -36,7 +36,7 @@ static void
gen_svr_tag(const char *name, size_t device_index, char *svr_tag)
{
int svr_tag_len =
snprintf(svr_tag, SVR_TAG_MAX, "%s_%ld", name, device_index);
snprintf(svr_tag, SVR_TAG_MAX, "%s_%zd", name, device_index);
svr_tag_len =
(svr_tag_len < SVR_TAG_MAX - 1) ? svr_tag_len + 1 : SVR_TAG_MAX - 1;
svr_tag[svr_tag_len] = '\0';
......@@ -239,7 +239,7 @@ oc_sec_load_ecdsa_keypair(size_t device)
oc_rep_set_pool(&rep_objects);
oc_parse_rep(buf, (uint16_t)ret, &rep);
if (oc_sec_decode_ecdsa_keypair(rep, device)) {
OC_DBG("successfully read ECDSA keypair for device %d", device);
OC_DBG("successfully read ECDSA keypair for device %zd", device);
}
oc_free_rep(rep);
}
......@@ -250,7 +250,7 @@ oc_sec_load_ecdsa_keypair(size_t device)
if (ret <= 0) {
if (oc_generate_ecdsa_keypair(device) < 0) {
OC_ERR("error generating ECDSA keypair for device %d", device);
OC_ERR("error generating ECDSA keypair for device %zd", device);
}
oc_sec_dump_ecdsa_keypair(device);
}
......
......@@ -515,8 +515,7 @@ next_cred_in_chain:
} else if (!id_cert->next) {
OC_DBG("new cert chains to known cert chain; Add cert to chain and "
"proceed...");
int ret =
mbedtls_x509_crt_parse_der(id_cert, cert->raw.p, cert->raw.len);
ret = mbedtls_x509_crt_parse_der(id_cert, cert->raw.p, cert->raw.len);
if (ret < 0) {
OC_WRN("could not parse cert in provided chain");
return true;
......@@ -582,7 +581,7 @@ add_new_identity_cert(oc_sec_cred_t *cred, size_t device)
(const unsigned char *)oc_cast(cred->privatedata.data, uint8_t),
oc_string_len(cred->privatedata.data) + 1, NULL, 0);
if (ret != 0) {
OC_ERR("could not parse private key %d",
OC_ERR("could not parse private key %zd",
oc_string_len(cred->privatedata.data));
goto add_new_identity_cert_error;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment