]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add CHECK_FREESPACE macro
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Feb 2018 17:32:56 +0000 (17:32 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Feb 2018 20:33:28 +0000 (20:33 +0000)
In general the internal encoder functions *should* return how much extra buffer they needed, so that their callers can make decisions about TLV nesting

src/include/proto.h

index 8493384f91ecfb74fbc3cf504a555272c21c8bff..1a5eccbc7fc06f41012274a76c690aee7888eaf6 100644 (file)
@@ -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)