Navigation Menu

Skip to content

Commit

Permalink
test: copy bytes into an uint64_t for strict-aliasing rules
Browse files Browse the repository at this point in the history
This change suppresses the following warning (gcc):
  test-table-patricia-trie-cursor.c: In function ‘geo_byte_parse’:
  test-table-patricia-trie-cursor.c:397:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       grn_ntog((uint8_t *)(&geo_point), geo_byte, sizeof(grn_geo_point));
       ^
  • Loading branch information
s-yata committed Feb 9, 2018
1 parent 6fd82e6 commit 4e752e7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/unit/core/test-table-patricia-trie-cursor.c
Expand Up @@ -377,6 +377,7 @@ geo_byte_parse(const gchar *geo_byte_string)
{
gint i = 0;
uint8_t geo_byte[sizeof(grn_geo_point)];
uint64_t geo_uint;
grn_geo_point geo_point;

while (geo_byte_string[0]) {
Expand All @@ -394,7 +395,8 @@ geo_byte_parse(const gchar *geo_byte_string)
}
geo_byte_string++;
}
grn_ntog((uint8_t *)(&geo_point), geo_byte, sizeof(grn_geo_point));
grn_memcpy(&geo_uint, geo_byte, sizeof(grn_geo_point));
grn_ntog((uint8_t *)(&geo_point), &geo_uint, sizeof(grn_geo_point));
return cut_take_printf("%dx%d",
geo_point.latitude,
geo_point.longitude);
Expand Down

0 comments on commit 4e752e7

Please sign in to comment.