]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_11] support autore in inline macro buffer functions
authorEvan Hunt <each@isc.org>
Thu, 2 Feb 2017 19:33:04 +0000 (11:33 -0800)
committerEvan Hunt <each@isc.org>
Thu, 2 Feb 2017 19:33:04 +0000 (11:33 -0800)
4565. [cleanup] The inline macro versions of isc_buffer_put*()
did not implement automatic buffer reallocation.
[RT #44216]

(cherry picked from commit 7769c929466d2cfda205fe2666ee5b2aaf4f3f44)

CHANGES
lib/isc/buffer.c
lib/isc/include/isc/buffer.h

diff --git a/CHANGES b/CHANGES
index 396a96be0915156e6d444af58c10cd846471aeb6..2e04003457ecb2c436086fdd6e6a514c994816be 100644 (file)
--- 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]
                        
index 1e2eac0cffff39cd873efa6ae20adacabdea9ca2..7337ab43e84b44352c31a0a2069d6bd905712dfd 100644 (file)
@@ -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);
index eb6684de06162cf4185716de69b5513972f5edb4..73e35a0e23ab288e9f528087b48d118ccec1d106 100644 (file)
@@ -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); \