]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
dbuff: Move the condition inside of the compound literal in FR_DBUFF_RESERVE
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 14 May 2020 18:26:08 +0000 (13:26 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 14 May 2020 18:28:58 +0000 (13:28 -0500)
src/lib/util/dbuff.h
src/lib/util/dbuff_tests.c

index 46cbaa65dc64bc43d875eb4ca3441d892cff220f..9ff01ef069d3a933e88223cf62ad8e733d584e9e 100644 (file)
@@ -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
  *
index 55a02a9a7fac1320577164f6cdeb6248825f42f7..5a2c6b13aa7b2e65a081924bab9be4a43a6df83e 100644 (file)
@@ -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));
 }