From: Arran Cudbard-Bell Date: Thu, 14 May 2020 18:26:08 +0000 (-0500) Subject: dbuff: Move the condition inside of the compound literal in FR_DBUFF_RESERVE X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db41e98a33a9f800259c26d76cd40d0166060f6d;p=thirdparty%2Ffreeradius-server.git dbuff: Move the condition inside of the compound literal in FR_DBUFF_RESERVE --- diff --git a/src/lib/util/dbuff.h b/src/lib/util/dbuff.h index 46cbaa65dc6..9ff01ef069d 100644 --- a/src/lib/util/dbuff.h +++ b/src/lib/util/dbuff.h @@ -99,7 +99,7 @@ struct fr_dbuff_s { /** Limit the maximum number of bytes available in the dbuff when passing it to another function * @code{.c} - my_child_encoder(FR_DBUFF_MAX(dbuff, 253), vp); + my_child_encoder(&FR_DBUFF_MAX(dbuff, 253), vp); @endcode * * @note Do not use to re-initialise the contents of #_dbuff, i.e. to @@ -111,9 +111,8 @@ struct fr_dbuff_s { * @param[in] _dbuff to reserve bytes in. * @param[in] _max The maximum number of bytes the caller is allowed to write to. */ -#define FR_DBUFF_MAX(_dbuff, _max) ((fr_dbuff_remaining(_dbuff) > (_max)) ? \ - &FR_DBUFF_RESERVE(_dbuff, fr_dbuff_remaining(_dbuff) - (_max)) : \ - _dbuff) +#define FR_DBUFF_MAX(_dbuff, _max) \ + FR_DBUFF_RESERVE(_dbuff, (fr_dbuff_remaining(_dbuff) > (_max)) ? (fr_dbuff_remaining(_dbuff) - (_max)) : 0) /** Does the actual work of initialising a dbuff * diff --git a/src/lib/util/dbuff_tests.c b/src/lib/util/dbuff_tests.c index 55a02a9a7fa..5a2c6b13aa7 100644 --- a/src/lib/util/dbuff_tests.c +++ b/src/lib/util/dbuff_tests.c @@ -46,16 +46,16 @@ static void test_dbuff_max(void) { uint8_t const in[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; fr_dbuff_t dbuff; - fr_dbuff_t *max_dbuff; + fr_dbuff_t max_dbuff; TEST_CASE("Confirm max constrains available space"); fr_dbuff_init(&dbuff, in, sizeof(in)); max_dbuff = FR_DBUFF_MAX(&dbuff, 4); - TEST_CHECK(fr_dbuff_remaining(max_dbuff) == 4); + TEST_CHECK(fr_dbuff_remaining(&max_dbuff) == 4); max_dbuff = FR_DBUFF_MAX(&dbuff, 2 * sizeof(in)); - TEST_CHECK(fr_dbuff_remaining(max_dbuff) == sizeof(in)); + TEST_CHECK(fr_dbuff_remaining(&max_dbuff) == sizeof(in)); }