* Round up x to a multiple of y; y must be a power of 2.
*/
#ifndef roundup2
-#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1)))
+#define roundup2(x, y) (((x)+((u_int)((y)-1)))&(~((u_int)((y)-1))))
#endif
#include <stdarg.h>
nd_uint16_t length;
};
-#define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
+#define F_ALN_LEN(len) roundup2(len, ForCES_ALNL)
#define GET_TOP_TLV(fhdr) ((const struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
#define TLV_SET_LEN(len) (F_ALN_LEN(TLV_HDRL) + (len))
#define TLV_DATA(tlvp) ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0)))
nd_print_invalid(ndo);
}
l += 17;
- l += -l & 3;
+ l = roundup2(l, 4);
if (bodylen >= l)
hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
}
}
skip_multiline:
- i += 4 + bodylen + (-bodylen & 3);
+ i += 4 + roundup2(bodylen, 4);
}
print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
parsefn(netdissect_options *ndo,
const uint32_t *dp)
{
- uint32_t len;
+ uint32_t len, rounded_len;
const u_char *cp;
/* Bail if we don't have the string length */
return NULL;
}
- ND_TCHECK_LEN(dp, ((len + 3) & ~3));
+ rounded_len = roundup2(len, 4);
+ ND_TCHECK_LEN(dp, rounded_len);
cp = (const u_char *)dp;
/* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
- dp += ((len + 3) & ~3) / sizeof(*dp);
+ dp += rounded_len / sizeof(*dp);
ND_PRINT("\"");
if (nd_printn(ndo, cp, len, ndo->ndo_snapend)) {
ND_PRINT("\"");
* an even multiple of DOP_ALIGN bytes, which must be a power of two.
*/
#define DOP_ALIGN 4
-#define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1))
+#define DOP_ROUNDUP(x) roundup2(x, DOP_ALIGN)
#define DOP_NEXT(d)\
((const struct dophdr *)((const u_char *)(d) + \
DOP_ROUNDUP(GET_BE_U_2((d)->dh_len) + sizeof(*(d)))))