diff --git a/CHANGES b/CHANGES index 6b3d562330..56c51bce25 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4565. [cleanup] The inline macro versions of isc_buffer_put*() + did not implement automatic buffer reallocation. + [RT #44216] + 4564. [maint] Update the built in managed keys to include the upcoming root KSK. [RT #44579] diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 1e2eac0cff..7337ab43e8 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -281,7 +281,7 @@ void isc__buffer_putuint8(isc_buffer_t *b, isc_uint8_t val) { isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, 1); REQUIRE(result == ISC_R_SUCCESS); } @@ -315,7 +315,7 @@ void isc__buffer_putuint16(isc_buffer_t *b, isc_uint16_t val) { isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, 2); REQUIRE(result == ISC_R_SUCCESS); } @@ -328,7 +328,7 @@ void isc__buffer_putuint24(isc_buffer_t *b, isc_uint32_t val) { isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, 3); REQUIRE(result == ISC_R_SUCCESS); } @@ -364,7 +364,7 @@ void isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val) { isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, 4); REQUIRE(result == ISC_R_SUCCESS); } @@ -405,7 +405,7 @@ isc__buffer_putuint48(isc_buffer_t *b, isc_uint64_t val) { isc_uint32_t vallo; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, 6); REQUIRE(result == ISC_R_SUCCESS); } @@ -423,7 +423,7 @@ isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base, { isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, length); REQUIRE(result == ISC_R_SUCCESS); } @@ -445,7 +445,7 @@ isc__buffer_putstr(isc_buffer_t *b, const char *source) { * Do not use ISC__BUFFER_PUTSTR(), so strlen is only done once. */ l = strlen(source); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, l); REQUIRE(result == ISC_R_SUCCESS); } @@ -468,7 +468,7 @@ isc_buffer_putdecint(isc_buffer_t *b, isc_int64_t v) { /* xxxwpk do it more low-level way ? */ l = snprintf(buf, 21, "%" ISC_PRINT_QUADFORMAT "d", v); RUNTIME_CHECK(l <= 21); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, l); REQUIRE(result == ISC_R_SUCCESS); } @@ -514,7 +514,7 @@ isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) { */ base = isc_buffer_used(b); available = isc_buffer_availablelength(b); - if (b->autore) { + if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, r->length); if (result != ISC_R_SUCCESS) return (result); diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index eb6684de06..73e35a0e23 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -876,6 +876,11 @@ ISC_LANG_ENDDECLS #define ISC__BUFFER_PUTMEM(_b, _base, _length) \ do { \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), _length) \ + == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= _length); \ memmove(isc_buffer_used(_b), (_base), (_length)); \ (_b)->used += (_length); \ } while (0) @@ -885,6 +890,11 @@ ISC_LANG_ENDDECLS unsigned int _length; \ unsigned char *_cp; \ _length = strlen(_source); \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), _length) \ + == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= _length); \ _cp = isc_buffer_used(_b); \ memmove(_cp, (_source), _length); \ (_b)->used += (_length); \ @@ -894,6 +904,11 @@ ISC_LANG_ENDDECLS do { \ unsigned char *_cp; \ isc_uint8_t _val2 = (_val); \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), 1) \ + == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= 1); \ _cp = isc_buffer_used(_b); \ (_b)->used++; \ _cp[0] = _val2 & 0x00ff; \ @@ -903,6 +918,10 @@ ISC_LANG_ENDDECLS do { \ unsigned char *_cp; \ isc_uint16_t _val2 = (_val); \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), 2) == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= 2); \ _cp = isc_buffer_used(_b); \ (_b)->used += 2; \ _cp[0] = (unsigned char)((_val2 & 0xff00U) >> 8); \ @@ -913,6 +932,11 @@ ISC_LANG_ENDDECLS do { \ unsigned char *_cp; \ isc_uint32_t _val2 = (_val); \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), 3) \ + == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= 3); \ _cp = isc_buffer_used(_b); \ (_b)->used += 3; \ _cp[0] = (unsigned char)((_val2 & 0xff0000U) >> 16); \ @@ -924,6 +948,11 @@ ISC_LANG_ENDDECLS do { \ unsigned char *_cp; \ isc_uint32_t _val2 = (_val); \ + if (ISC_UNLIKELY((_b)->autore)) { \ + REQUIRE(isc_buffer_reserve(&(_b), 4) \ + == ISC_R_SUCCESS); \ + } \ + REQUIRE(isc_buffer_availablelength(_b) >= 4); \ _cp = isc_buffer_used(_b); \ (_b)->used += 4; \ _cp[0] = (unsigned char)((_val2 & 0xff000000) >> 24); \