From: Arran Cudbard-Bell Date: Thu, 15 Feb 2018 17:32:56 +0000 (+0000) Subject: Add CHECK_FREESPACE macro X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95454c948236264ca41c3748ca4bc1661829b282;p=thirdparty%2Ffreeradius-server.git Add CHECK_FREESPACE macro In general the internal encoder functions *should* return how much extra buffer they needed, so that their callers can make decisions about TLV nesting --- diff --git a/src/include/proto.h b/src/include/proto.h index 8493384f91e..1a5eccbc7fc 100644 --- a/src/include/proto.h +++ b/src/include/proto.h @@ -31,6 +31,11 @@ RCSIDH(proto_h, "$Id$") extern "C" { #endif +#define CHECK_FREESPACE(_have, _need) \ +do { \ + if (unlikely((size_t)(_have) < (size_t)(_need))) return -((size_t)(_need) - (size_t)(_have)); \ +} while (0); + #ifndef NDEBUG # define FR_PROTO_TRACE(_x, ...) if (fr_log_fp && (fr_debug_lvl > 3)) fr_proto_print(__FILE__, __LINE__, _x, ## __VA_ARGS__) # define FR_PROTO_HEX_DUMP(_x, _y, _z) if (fr_log_fp && (fr_debug_lvl > 3)) fr_proto_print_hex_data(__FILE__, __LINE__, _x, _y, _z)