Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Fix for Unsigned long long usage in 32bit arch #999

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ WARNINGS = \
-Winit-self \
-Winline \
-Winvalid-pch \
-Wlong-long \
-Wmissing-field-initializers \
-Wmissing-format-attribute \
-Wmissing-include-dirs \
Expand Down
27 changes: 16 additions & 11 deletions meta/saiserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ int sai_serialize_uint64(
_Out_ char *buffer,
_In_ uint64_t u64)
{
return sprintf(buffer, "%lu", u64);
return sprintf(buffer, "%"PRIu64, u64);
}

#define SAI_BASE_10 10
Expand Down Expand Up @@ -372,7 +372,7 @@ int sai_serialize_int64(
_Out_ char *buffer,
_In_ int64_t s64)
{
return sprintf(buffer, "%ld", s64);
return sprintf(buffer, "%"PRId64, s64);
}

int sai_deserialize_int64(
Expand Down Expand Up @@ -443,7 +443,7 @@ int sai_serialize_object_id(
_Out_ char *buffer,
_In_ sai_object_id_t oid)
{
return sprintf(buffer, "oid:0x%lx", oid);
return sprintf(buffer, "oid:0x%"PRIx64, oid);
}

int sai_deserialize_object_id(
Expand All @@ -452,7 +452,7 @@ int sai_deserialize_object_id(
{
int read;

int n = sscanf(buffer, "oid:0x%16lx%n", oid, &read);
int n = sscanf(buffer, "oid:0x%16"PRIx64"%n", oid, &read);

if (n == 1 && sai_serialize_is_char_allowed(buffer[read]))
{
Expand Down Expand Up @@ -850,10 +850,12 @@ int sai_serialize_ip6_mask(
_In_ const sai_ip6_t mask)
{
uint32_t n = 64;
uint64_t tmp = 0xFFFFFFFFFFFFFFFFUL;
uint64_t tmp = UINT64_C(0xFFFFFFFFFFFFFFFF);

uint64_t high = *((const uint64_t*)mask);
uint64_t low = *((const uint64_t*)mask + 1);
uint64_t high;
uint64_t low;
memcpy(&high, (const uint8_t*)mask, sizeof(uint64_t));
memcpy(&low, ((const uint8_t*)mask + sizeof(uint64_t)), sizeof(uint64_t));

high = __builtin_bswap64(high);
low = __builtin_bswap64(low);
Expand Down Expand Up @@ -899,8 +901,9 @@ int sai_deserialize_ip6_mask(
return SAI_SERIALIZE_ERROR;
}

uint64_t high = 0xFFFFFFFFFFFFFFFFUL;
uint64_t low = 0xFFFFFFFFFFFFFFFFUL;
uint64_t high = UINT64_C(0xFFFFFFFFFFFFFFFF);
uint64_t low = UINT64_C(0xFFFFFFFFFFFFFFFF);
uint64_t tmp;

if (value == 128)
{
Expand All @@ -924,8 +927,10 @@ int sai_deserialize_ip6_mask(
low = 0;
}

*((uint64_t*)mask) = __builtin_bswap64(high);
*((uint64_t*)mask + 1) = __builtin_bswap64(low);
tmp = __builtin_bswap64(high);
memcpy((uint8_t*)mask, &tmp, sizeof(uint64_t));
tmp = __builtin_bswap64(low);
memcpy(((uint8_t*)mask + sizeof(uint64_t)), &tmp, sizeof(uint64_t));

return res;
}
Expand Down
3 changes: 2 additions & 1 deletion meta/saiserializetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @brief This module defines SAI Serialize Test
*/

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand Down Expand Up @@ -228,7 +229,7 @@ void test_deserialize_object_id()

sai_object_id_t ref;
int len;
sscanf(valid_oids[n], "oid:0x%lx%n", &ref, &len);
sscanf(valid_oids[n], "oid:0x%"PRIx64"%n", &ref, &len);

ASSERT_TRUE(res == len, "expected true");
ASSERT_TRUE(oid == ref, "expected true");
Expand Down