Skip to content

Commit

Permalink
Update Android compilation
Browse files Browse the repository at this point in the history
Fix compilation on supported Android environments.
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Sep 26, 2023
1 parent f8fac5e commit 3ff55e7
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 144 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ on:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
ndk-version:
description: NDK version
required: false
type: choice
default: r26
options:
- r21
- r22
- r23
- r24
- r25
- r26

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down Expand Up @@ -57,7 +70,7 @@ jobs:
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r25
ndk-version: ${{ (github.event_name == 'workflow_dispatch' && inputs.ndk-version) || 'r26' }}

# Runs a set of commands using the runners shell
- name: build
Expand Down
2 changes: 1 addition & 1 deletion api/cloud/unittest/cloud_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestCloudManager : public testing::Test {

TEST_F(TestCloudManager, cloud_manager_start_initialized_without_retry_f)
{
uint8_t retry_original[6] = { 0 };
uint8_t retry_original[6]{};
size_t retry_original_size = cloud_manager_get_retry(
retry_original, sizeof(retry_original) / sizeof(retry_original[0]));
EXPECT_NE((size_t)-1, retry_original_size);
Expand Down
7 changes: 5 additions & 2 deletions api/oc_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,12 @@ oc_handle_collection_batch_request(oc_method_t method, oc_request_t *request,
int pcode = oc_status_code(OC_STATUS_BAD_REQUEST);
CborEncoder encoder;
CborEncoder prev_link;
oc_request_t rest_request = { 0 };
oc_response_t response = { 0 };
oc_request_t rest_request;
memset(&rest_request, 0, sizeof(oc_request_t));
oc_response_t response;
memset(&response, 0, sizeof(oc_response_t));
oc_response_buffer_t response_buffer;
memset(&response_buffer, 0, sizeof(oc_response_buffer_t));
bool method_not_found = false;
bool get_delete = false;
const oc_rep_t *rep = request->request_payload;
Expand Down
15 changes: 10 additions & 5 deletions api/oc_core_res.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@
static oc_resource_t *g_core_resources = NULL;
static oc_device_info_t *g_oc_device_info = NULL;
#else /* OC_DYNAMIC_ALLOCATION */
static oc_resource_t
g_core_resources[OC_NUM_CORE_PLATFORM_RESOURCES +
(OC_NUM_CORE_LOGICAL_DEVICE_RESOURCES * OC_MAX_NUM_DEVICES)];
static oc_device_info_t g_oc_device_info[OC_MAX_NUM_DEVICES];
static oc_resource_t g_core_resources[OC_NUM_CORE_PLATFORM_RESOURCES +
(OC_NUM_CORE_LOGICAL_DEVICE_RESOURCES *
OC_MAX_NUM_DEVICES)] = { 0 };
static oc_device_info_t g_oc_device_info[OC_MAX_NUM_DEVICES] = { 0 };
#endif /* !OC_DYNAMIC_ALLOCATION */
static oc_platform_info_t g_oc_platform_info = { 0 };
static oc_platform_info_t g_oc_platform_info = {
.pi = { { 0 } },
.mfg_name = { 0 },
.init_platform_cb = NULL,
.data = NULL,
};

static int g_res_latency = 0;
static OC_ATOMIC_UINT32_T g_device_count = 0;
Expand Down
7 changes: 5 additions & 2 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,12 @@ process_batch_response(CborEncoder *links_array, oc_resource_t *resource,
!oc_discovery_resource_is_in_batch_response(resource, endpoint, true)) {
return;
}
oc_request_t rest_request = { 0 };
oc_response_t response = { 0 };
oc_request_t rest_request;
memset(&rest_request, 0, sizeof(oc_request_t));
oc_response_t response;
memset(&response, 0, sizeof(oc_response_t));
oc_response_buffer_t response_buffer;
memset(&response_buffer, 0, sizeof(oc_response_buffer_t));
response.response_buffer = &response_buffer;
rest_request.response = &response;
rest_request.origin = endpoint;
Expand Down
3 changes: 2 additions & 1 deletion api/oc_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ static int
oc_parse_endpoint_string(const oc_string_t *endpoint_str,
oc_endpoint_t *endpoint, oc_string_t *uri)
{
endpoint_uri_t ep_uri = { 0 };
endpoint_uri_t ep_uri;
memset(&ep_uri, 0, sizeof(endpoint_uri_t));
if (!parse_endpoint_uri(endpoint_str, &ep_uri, uri != NULL)) {
return -1;
}
Expand Down
9 changes: 6 additions & 3 deletions api/oc_swupdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,10 @@ swupdate_decode(const oc_rep_t *rep, int flags, bool has_purl,
bool
oc_swupdate_decode(const oc_rep_t *rep, int flags, oc_swupdate_t *dst)
{
oc_swupdate_on_error_t on_error = { NULL, NULL };
oc_swupdate_decode_t swudecode = { 0 };
oc_swupdate_on_error_t on_error;
memset(&on_error, 0, sizeof(on_error));
oc_swupdate_decode_t swudecode;
memset(&swudecode, 0, sizeof(swudecode));
if (!swupdate_decode(rep, flags, oc_string(dst->purl) != NULL, on_error,
&swudecode)) {
return false;
Expand All @@ -782,7 +784,8 @@ oc_swupdate_validate_update(size_t device, const oc_rep_t *rep,
.fn = on_error,
.data = on_error_data,
};
oc_swupdate_decode_t swudecode = { 0 };
oc_swupdate_decode_t swudecode;
memset(&swudecode, 0, sizeof(swudecode));
return swupdate_decode(rep, OC_SWUPDATE_DECODE_FLAG_VALIDATE_DECODED_DATA,
oc_string(g_sw[device].purl) != NULL, on_error_impl,
&swudecode);
Expand Down
14 changes: 11 additions & 3 deletions api/plgd/plgd_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ OC_MEMB(g_time_verify_certificate_params_s, time_verify_certificate_params_t,

#endif /* OC_CLIENT */

static plgd_time_t g_oc_plgd_time = { 0 };
static plgd_time_t g_oc_plgd_time = {
.store = { 0 },
.status = 0,
.update_time = 0,
.set_system_time = NULL,
.set_system_time_data = NULL,
};

plgd_time_t *
plgd_time_get(void)
Expand Down Expand Up @@ -511,7 +517,8 @@ store_decode_plgd_time(const oc_rep_t *rep, size_t device, void *data)
bool
plgd_time_load(void)
{
plgd_time_t pt = { 0 };
plgd_time_t pt;
memset(&pt, 0, sizeof(pt));
if (oc_storage_data_load(PLGD_TIME_STORE_NAME, 0, store_decode_plgd_time,
&pt) <= 0) {
OC_DBG("failed to load plgd-time from storage");
Expand All @@ -532,7 +539,8 @@ plgd_time_resource_post(oc_request_t *request, oc_interface_mask_t iface_mask,
{
(void)iface_mask;
(void)data;
plgd_time_t pt = { 0 };
plgd_time_t pt;
memset(&pt, 0, sizeof(pt));
if (!plgd_time_decode(request->request_payload, &pt)) {
OC_ERR("cannot decode data for plgd-time resource");
oc_send_response_with_callback(request, OC_STATUS_BAD_REQUEST, true);
Expand Down
4 changes: 2 additions & 2 deletions apps/cloud_certification_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ struct switch_t
bool state;
};

static struct switch_t bswitch = { 0 };
static struct switch_t bswitch = { false };

static void
get_switch(oc_request_t *request, oc_interface_mask_t iface_mask,
Expand Down Expand Up @@ -469,7 +469,7 @@ register_resources(void)
}

static oc_resource_t *reg_resource = NULL;
static struct switch_t reg_bswitch = { 0 };
static struct switch_t reg_bswitch = { false };

static void
add_resource(void)
Expand Down
3 changes: 2 additions & 1 deletion messaging/coap/observe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ coap_process_discovery_batch_observers(void)
oc_rep_new_v1(response_buffer.buffer, response_buffer.buffer_size);
#endif /* !OC_DYNAMIC_ALLOCATION */
if (observe_batch_set_response_buffer(batch_obs, &response_buffer)) {
oc_response_t response = { 0 };
oc_response_t response;
memset(&response, 0, sizeof(response));
response.response_buffer = &response_buffer;
if (notify_batch_observer(obs, &response) < 0) {
goto leave_notify_observers;
Expand Down
2 changes: 1 addition & 1 deletion port/android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ DTLS= \
x509_csr.c platform_util.c ssl_msg.c constant_time.c \
nist_kw.c aria.c rsa_alt_helpers.c

DTLSFLAGS=-I../../deps/mbedtls/include
DTLSFLAGS=-I../../deps/mbedtls/include -Wno-error=unused

CBOR=../../deps/tinycbor/src/cborencoder.c ../../deps/tinycbor/src/cborencoder_close_container_checked.c ../../deps/tinycbor/src/cborencoder_float.c ../../deps/tinycbor/src/cborparser.c ../../deps/tinycbor/src/cborparser_float.c# ../../deps/tinycbor/src/cbortojson.c ../../deps/tinycbor/src/cborpretty.c ../../deps/tinycbor/src/cborparser_dup_string.c

Expand Down
18 changes: 9 additions & 9 deletions port/android/ifaddrs-android.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ struct netlinkrequest
struct ifaddrmsg msg;
};

static const int kMaxReadSize = 4096;

static int
set_ifname(struct ifaddrs *ifaddr, int interface)
{
Expand Down Expand Up @@ -111,7 +109,7 @@ set_addresses(struct ifaddrs *ifaddr, struct ifaddrmsg *msg, void *data,
static int
make_prefixes(struct ifaddrs *ifaddr, int family, int prefixlen)
{
char *prefix = NULL;
unsigned char *prefix = NULL;
if (family == AF_INET) {
struct sockaddr_in *mask = malloc(sizeof(struct sockaddr_in));
memset(mask, 0, sizeof(struct sockaddr_in));
Expand All @@ -121,7 +119,7 @@ make_prefixes(struct ifaddrs *ifaddr, int family, int prefixlen)
if (prefixlen > 32) {
prefixlen = 32;
}
prefix = (char *)&mask->sin_addr;
prefix = (unsigned char *)&mask->sin_addr;
} else if (family == AF_INET6) {
struct sockaddr_in6 *mask = malloc(sizeof(struct sockaddr_in6));
memset(mask, 0, sizeof(struct sockaddr_in6));
Expand All @@ -131,14 +129,14 @@ make_prefixes(struct ifaddrs *ifaddr, int family, int prefixlen)
if (prefixlen > 128) {
prefixlen = 128;
}
prefix = (char *)&mask->sin6_addr;
prefix = (unsigned char *)&mask->sin6_addr;
} else {
return -1;
}
for (int i = 0; i < (prefixlen / 8); i++) {
*prefix++ = 0xFF;
}
char remainder = 0xff;
unsigned char remainder = 0xFF;
remainder <<= (8 - prefixlen % 8);
*prefix = remainder;
return 0;
Expand Down Expand Up @@ -184,8 +182,10 @@ android_getifaddrs(struct ifaddrs **result)
}
struct ifaddrs *start = NULL;
struct ifaddrs *current = NULL;
char buf[kMaxReadSize];
ssize_t amount_read = recv(fd, &buf, kMaxReadSize, 0);
#define MAX_READ_SIZE (4096)
char buf[MAX_READ_SIZE] = { 0 };
#undef MAX_READ_SIZE
ssize_t amount_read = recv(fd, &buf, OC_ARRAY_SIZE(buf), 0);
while (amount_read > 0) {
struct nlmsghdr *header = (struct nlmsghdr *)&buf[0];
size_t header_size = (size_t)amount_read;
Expand Down Expand Up @@ -234,7 +234,7 @@ android_getifaddrs(struct ifaddrs **result)
}
}
}
amount_read = recv(fd, &buf, kMaxReadSize, 0);
amount_read = recv(fd, &buf, OC_ARRAY_SIZE(buf), 0);
}
close(fd);
android_freeifaddrs(start);
Expand Down
12 changes: 6 additions & 6 deletions port/esp32/adapter/src/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ get_ip_context_for_device(size_t device)
static int
add_mcast_sock_to_ipv4_mcast_group(int mcast_sock, const esp_ip4_addr_t *local)
{
struct ip_mreq imreq = { 0 };
int err = 0;
// Configure source interface
struct ip_mreq imreq;
memset(&imreq, 0, sizeof(struct ip_mreq));
// Configure source interface
inet_addr_from_ip4addr(&imreq.imr_interface, local);
imreq.imr_multiaddr.s_addr = htonl(ALL_COAP_NODES_V4);
OC_DBG("Configured IPV4 Multicast address %s",
Expand All @@ -253,8 +252,8 @@ add_mcast_sock_to_ipv4_mcast_group(int mcast_sock, const esp_ip4_addr_t *local)
return -1;
}

err = setsockopt(mcast_sock, IPPROTO_IP, IP_MULTICAST_IF,
&imreq.imr_interface, sizeof(struct in_addr));
int err = setsockopt(mcast_sock, IPPROTO_IP, IP_MULTICAST_IF,
&imreq.imr_interface, sizeof(struct in_addr));
if (err < 0) {
OC_ERR("setsockopt IP_MULTICAST_IF ret:%d", err);
return -1;
Expand Down Expand Up @@ -421,7 +420,8 @@ get_interface_addresses(ip_context_t *dev, unsigned char family, uint16_t port,
{
for (esp_netif_t *esp_netif = esp_netif_next(NULL); esp_netif;
esp_netif = esp_netif_next(esp_netif)) {
oc_endpoint_t ep = { 0 };
oc_endpoint_t ep;
memset(&ep, 0, sizeof(oc_endpoint_t));
int if_index = esp_netif_get_netif_impl_index(esp_netif);
if (if_index < 0) {
OC_ERR("esp_netif_get_netif_impl_index returns error");
Expand Down
2 changes: 1 addition & 1 deletion port/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ DTLS= aes.c aesni.c asn1parse.c asn1write.c base64.c \
ssl_srv.c ssl_ticket.c ssl_tls.c x509write_csr.c\
x509write_crt.c x509_create.c x509_csr.c ssl_msg.c constant_time.c \
nist_kw.c aria.c rsa_alt_helpers.c
DTLSFLAGS=-I../../deps/mbedtls/include
DTLSFLAGS=-I../../deps/mbedtls/include -Wno-error=unused

CBOR_DIR=../../deps/tinycbor/src
CBOR=$(CBOR_DIR)/cborencoder.c $(CBOR_DIR)/cborencoder_close_container_checked.c \
Expand Down
3 changes: 2 additions & 1 deletion port/windows/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ get_interface_addresses(ifaddr_t *ifaddr_list, ip_context_t *dev,
{
ifaddr_t *ifaddr;

oc_endpoint_t ep = { 0 };
oc_endpoint_t ep;
memset(&ep, 0, sizeof(oc_endpoint_t));

if (secure) {
ep.flags = SECURED;
Expand Down
2 changes: 1 addition & 1 deletion security/oc_doxm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

#ifdef OC_DYNAMIC_ALLOCATION
#include <stdlib.h>
static oc_sec_doxm_t *g_doxm;
static oc_sec_doxm_t *g_doxm = NULL;
#else /* OC_DYNAMIC_ALLOCATION */
static oc_sec_doxm_t g_doxm[OC_MAX_NUM_DEVICES] = { 0 };
#endif /* !OC_DYNAMIC_ALLOCATION */
Expand Down
3 changes: 2 additions & 1 deletion security/oc_obt.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ get_endpoints(oc_client_response_t *data)
return;
}

oc_uuid_t di = { 0 };
oc_uuid_t di;
memset(&di, 0, sizeof(oc_uuid_t));
// skip "ocf://" prefix
oc_str_to_uuid(oc_string(*anchor) + 6, &di);
const oc_uuid_t *my_uuid = oc_core_get_device_id(0);
Expand Down
3 changes: 2 additions & 1 deletion security/oc_sdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ oc_sec_sdi_decode_with_state(const oc_rep_t *rep, oc_dostype_t state,
{
assert(sdi != NULL);

sdi_decode_data_t sdi_data = { 0 };
sdi_decode_data_t sdi_data;
memset(&sdi_data, 0, sizeof(sdi_data));
for (; rep != NULL; rep = rep->next) {
switch (rep->type) {
case OC_REP_STRING:
Expand Down
Loading

0 comments on commit 3ff55e7

Please sign in to comment.