From: Vincent Bernat Date: Thu, 19 Feb 2015 16:28:00 +0000 (+0100) Subject: check: enforce correct alignment during SNMP tests X-Git-Tag: 0.7.14~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47cd2807872aea1de7ba286156c359a4d0f61f89;p=thirdparty%2Flldpd.git check: enforce correct alignment during SNMP tests This should fix the following clang error, despite the fact that we know that the alignment was correct: ``` check_snmp.c:900:9: fatal error: cast from 'u_char *' (aka 'unsigned char *') to 'unsigned long *' increases required alignment from 1 to 8 [-Wcast-align] *(unsigned long int *)result, ^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/check.h:220:22: note: expanded from macro 'fail_unless' _fail_unless(expr, __FILE__, __LINE__,\ ^ 1 error generated. ``` --- diff --git a/tests/check_snmp.c b/tests/check_snmp.c index c82ad15c..f05cdce3 100644 --- a/tests/check_snmp.c +++ b/tests/check_snmp.c @@ -881,6 +881,7 @@ snmp_compare(struct tree_node *n, u_char *result, size_t varlen, oid *target, size_t targetlen, char *repr) { + unsigned long int value; fail_unless((targetlen == sizeof(lldp_oid)/sizeof(oid) + n->namelen) && !memcmp(target, lldp_oid, sizeof(lldp_oid)) && !memcmp(target + sizeof(lldp_oid)/sizeof(oid), @@ -896,12 +897,12 @@ snmp_compare(struct tree_node *n, fail_unless(varlen == sizeof(unsigned long int), "Inappropriate length for integer type for OID %s", repr); - fail_unless(n->value.integer == - *(unsigned long int *)result, + memcpy(&value, result, sizeof(value)); + fail_unless(n->value.integer == value, "For OID %s, expected value %u but got %u instead", repr, n->value.integer, - *(unsigned long int *)result); + value); break; default: fail_unless(((n->value.string.len == varlen) &&