Skip to content

Commit 83af4e0

Browse files
DNS: Cast void* to intptr_t in nsapi_dns.cpp
This is for portability reasons. If this code was compiled to a 64-bit architecture, then the cast from void* to int would lose precision.
1 parent c018b2b commit 83af4e0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

features/netsocket/nsapi_dns.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <string.h>
2424
#include <stdlib.h>
2525
#include <stdio.h>
26+
#include <stdint.h>
2627
#include "mbed_shared_queues.h"
2728
#include "events/EventQueue.h"
2829
#include "OnboardNetworkStack.h"
@@ -63,7 +64,7 @@ enum dns_state {
6364
};
6465

6566
struct DNS_QUERY {
66-
int unique_id;
67+
intptr_t unique_id;
6768
nsapi_error_t status;
6869
NetworkStack *stack;
6970
char *host;
@@ -94,7 +95,7 @@ static void nsapi_dns_cache_reset();
9495
static nsapi_error_t nsapi_dns_get_server_addr(NetworkStack *stack, uint8_t *index, uint8_t *total_attempts, uint8_t *send_success, SocketAddress *dns_addr, const char *interface_name);
9596

9697
static void nsapi_dns_query_async_create(void *ptr);
97-
static nsapi_error_t nsapi_dns_query_async_delete(int unique_id);
98+
static nsapi_error_t nsapi_dns_query_async_delete(intptr_t unique_id);
9899
static void nsapi_dns_query_async_send(void *ptr);
99100
static void nsapi_dns_query_async_timeout(void);
100101
static void nsapi_dns_query_async_resp(DNS_QUERY *query, nsapi_error_t status, SocketAddress *address);
@@ -122,7 +123,7 @@ static SingletonPtr<PlatformMutex> dns_cache_mutex;
122123
#endif
123124

124125
static uint16_t dns_message_id = 1;
125-
static int dns_unique_id = 1;
126+
static intptr_t dns_unique_id = 1;
126127
static DNS_QUERY *dns_query_queue[DNS_QUERY_QUEUE_SIZE];
127128
// Protects from several threads running asynchronous DNS
128129
static SingletonPtr<PlatformMutex> dns_mutex;
@@ -765,7 +766,7 @@ nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const
765766

766767
static void nsapi_dns_query_async_initiate_next(void)
767768
{
768-
int id = INT32_MAX;
769+
intptr_t id = INTPTR_MAX;
769770
DNS_QUERY *query = NULL;
770771

771772
// Trigger next query to start, find one that has been on queue longest
@@ -842,7 +843,7 @@ static void nsapi_dns_query_async_timeout(void)
842843
dns_mutex->unlock();
843844
}
844845

845-
nsapi_error_t nsapi_dns_query_async_cancel(int id)
846+
nsapi_error_t nsapi_dns_query_async_cancel(intptr_t id)
846847
{
847848
dns_mutex->lock();
848849

@@ -874,7 +875,7 @@ static void nsapi_dns_query_async_create(void *ptr)
874875
{
875876
dns_mutex->lock();
876877

877-
int unique_id = reinterpret_cast<int>(ptr);
878+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
878879

879880
DNS_QUERY *query = NULL;
880881

@@ -940,7 +941,7 @@ static void nsapi_dns_query_async_create(void *ptr)
940941

941942
}
942943

943-
static nsapi_error_t nsapi_dns_query_async_delete(int unique_id)
944+
static nsapi_error_t nsapi_dns_query_async_delete(intptr_t unique_id)
944945
{
945946
int index = -1;
946947
DNS_QUERY *query = NULL;
@@ -1000,7 +1001,7 @@ static void nsapi_dns_query_async_send(void *ptr)
10001001
{
10011002
dns_mutex->lock();
10021003

1003-
int unique_id = reinterpret_cast<int>(ptr);
1004+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
10041005

10051006
DNS_QUERY *query = NULL;
10061007

@@ -1162,7 +1163,7 @@ static void nsapi_dns_query_async_response(void *ptr)
11621163
{
11631164
dns_mutex->lock();
11641165

1165-
int unique_id = reinterpret_cast<int>(ptr);
1166+
intptr_t unique_id = reinterpret_cast<intptr_t>(ptr);
11661167

11671168
DNS_QUERY *query = NULL;
11681169

0 commit comments

Comments
 (0)