* Make 'b' refer to the 'length'-byte region starting at 'base'.
* XXXDCL see the comment in buffer.h about base being const.
*/
-
- REQUIRE(b != NULL);
-
ISC__BUFFER_INIT(b, base, length);
}
* Initialize a new buffer which has no backing store. This can
* later be grown as needed and swapped in place.
*/
-
ISC__BUFFER_INIT(b, NULL, 0);
}
/*
* Make 'b' an invalid buffer.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(!ISC_LINK_LINKED(b, link));
- REQUIRE(b->mctx == NULL);
-
ISC__BUFFER_INVALIDATE(b);
}
/*
* Make 'r' refer to the region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_REGION(b, r);
}
/*
* Make 'r' refer to the used region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_USEDREGION(b, r);
}
/*
* Make 'r' refer to the available region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_AVAILABLEREGION(b, r);
}
/*
* Increase the 'used' region of 'b' by 'n' bytes.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(b->used + n <= b->length);
-
ISC__BUFFER_ADD(b, n);
}
/*
* Decrease the 'used' region of 'b' by 'n' bytes.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(b->used >= n);
-
ISC__BUFFER_SUBTRACT(b, n);
}
/*
* Make the used region empty.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
-
ISC__BUFFER_CLEAR(b);
}
/*
* Make 'r' refer to the consumed region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_CONSUMEDREGION(b, r);
}
/*
* Make 'r' refer to the remaining region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_REMAININGREGION(b, r);
}
/*
* Make 'r' refer to the active region of 'b'.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(r != NULL);
-
ISC__BUFFER_ACTIVEREGION(b, r);
}
/*
* Sets the end of the active region 'n' bytes after current.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(b->current + n <= b->used);
-
ISC__BUFFER_SETACTIVE(b, n);
}
/*
* Make the consumed region empty.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
-
ISC__BUFFER_FIRST(b);
}
/*
* Increase the 'consumed' region of 'b' by 'n' bytes.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(b->current + n <= b->used);
-
ISC__BUFFER_FORWARD(b, n);
}
/*
* Decrease the 'consumed' region of 'b' by 'n' bytes.
*/
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(n <= b->current);
-
ISC__BUFFER_BACK(b, n);
}
void
isc__buffer_putuint8(isc_buffer_t *b, uint8_t val) {
- isc_result_t result;
- REQUIRE(ISC_BUFFER_VALID(b));
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, 1);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= 1);
-
ISC__BUFFER_PUTUINT8(b, val);
}
void
isc__buffer_putuint16(isc_buffer_t *b, uint16_t val) {
- isc_result_t result;
- REQUIRE(ISC_BUFFER_VALID(b));
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, 2);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= 2);
-
ISC__BUFFER_PUTUINT16(b, val);
}
void
isc__buffer_putuint24(isc_buffer_t *b, uint32_t val) {
- isc_result_t result;
- REQUIRE(ISC_BUFFER_VALID(b));
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, 3);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= 3);
-
ISC__BUFFER_PUTUINT24(b, val);
}
void
isc__buffer_putuint32(isc_buffer_t *b, uint32_t val) {
- isc_result_t result;
- REQUIRE(ISC_BUFFER_VALID(b));
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, 4);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= 4);
-
ISC__BUFFER_PUTUINT32(b, val);
}
void
isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base,
unsigned int length) {
- isc_result_t result;
- REQUIRE(ISC_BUFFER_VALID(b));
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, length);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= length);
-
ISC__BUFFER_PUTMEM(b, base, length);
}
void
isc__buffer_putstr(isc_buffer_t *b, const char *source) {
- unsigned int l;
- unsigned char *cp;
- isc_result_t result;
-
- REQUIRE(ISC_BUFFER_VALID(b));
- REQUIRE(source != NULL);
-
- /*
- * Do not use ISC__BUFFER_PUTSTR(), so strlen is only done once.
- */
- l = strlen(source);
- if (ISC_UNLIKELY(b->autore)) {
- result = isc_buffer_reserve(&b, l);
- REQUIRE(result == ISC_R_SUCCESS);
- }
- REQUIRE(isc_buffer_availablelength(b) >= l);
-
- cp = isc_buffer_used(b);
- memmove(cp, source, l);
- b->used += l;
+ ISC__BUFFER_PUTSTR(b, source);
}
void
#include <isc/formatcheck.h>
#include <isc/lang.h>
#include <isc/likely.h>
+#include <isc/list.h>
#include <isc/magic.h>
#include <isc/types.h>
*/
#define ISC__BUFFER_INIT(_b, _base, _length) \
do { \
+ ISC_REQUIRE((_b) != NULL); \
(_b)->base = _base; \
(_b)->length = (_length); \
(_b)->used = 0; \
#define ISC__BUFFER_INITNULL(_b) ISC__BUFFER_INIT(_b, NULL, 0)
-#define ISC__BUFFER_INVALIDATE(_b) \
- do { \
- (_b)->magic = 0; \
- (_b)->base = NULL; \
- (_b)->length = 0; \
- (_b)->used = 0; \
- (_b)->current = 0; \
- (_b)->active = 0; \
+#define ISC__BUFFER_INVALIDATE(_b) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE(!ISC_LINK_LINKED((_b), link)); \
+ ISC_REQUIRE((_b)->mctx == NULL); \
+ (_b)->magic = 0; \
+ (_b)->base = NULL; \
+ (_b)->length = 0; \
+ (_b)->used = 0; \
+ (_b)->current = 0; \
+ (_b)->active = 0; \
} while (0)
-#define ISC__BUFFER_REGION(_b, _r) \
- do { \
- (_r)->base = (_b)->base; \
- (_r)->length = (_b)->length; \
+#define ISC__BUFFER_REGION(_b, _r) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
+ (_r)->base = (_b)->base; \
+ (_r)->length = (_b)->length; \
} while (0)
-#define ISC__BUFFER_USEDREGION(_b, _r) \
- do { \
- (_r)->base = (_b)->base; \
- (_r)->length = (_b)->used; \
+#define ISC__BUFFER_USEDREGION(_b, _r) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
+ (_r)->base = (_b)->base; \
+ (_r)->length = (_b)->used; \
} while (0)
#define ISC__BUFFER_AVAILABLEREGION(_b, _r) \
do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
(_r)->base = isc_buffer_used(_b); \
(_r)->length = isc_buffer_availablelength(_b); \
} while (0)
-#define ISC__BUFFER_ADD(_b, _n) \
- do { \
- (_b)->used += (_n); \
+#define ISC__BUFFER_ADD(_b, _n) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_b)->used + (_n) <= (_b)->length); \
+ (_b)->used += (_n); \
} while (0)
#define ISC__BUFFER_SUBTRACT(_b, _n) \
do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_b)->used >= (_n)); \
(_b)->used -= (_n); \
if ((_b)->current > (_b)->used) \
(_b)->current = (_b)->used; \
(_b)->active = (_b)->used; \
} while (0)
-#define ISC__BUFFER_CLEAR(_b) \
- do { \
- (_b)->used = 0; \
- (_b)->current = 0; \
- (_b)->active = 0; \
+#define ISC__BUFFER_CLEAR(_b) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ (_b)->used = 0; \
+ (_b)->current = 0; \
+ (_b)->active = 0; \
} while (0)
-#define ISC__BUFFER_CONSUMEDREGION(_b, _r) \
- do { \
- (_r)->base = (_b)->base; \
- (_r)->length = (_b)->current; \
+#define ISC__BUFFER_CONSUMEDREGION(_b, _r) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
+ (_r)->base = (_b)->base; \
+ (_r)->length = (_b)->current; \
} while (0)
#define ISC__BUFFER_REMAININGREGION(_b, _r) \
do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
(_r)->base = isc_buffer_current(_b); \
(_r)->length = isc_buffer_remaininglength(_b); \
} while (0)
#define ISC__BUFFER_ACTIVEREGION(_b, _r) \
do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_r) != NULL); \
if ((_b)->current < (_b)->active) { \
(_r)->base = isc_buffer_current(_b); \
(_r)->length = isc_buffer_activelength(_b); \
} \
} while (0)
-#define ISC__BUFFER_SETACTIVE(_b, _n) \
- do { \
- (_b)->active = (_b)->current + (_n); \
+#define ISC__BUFFER_SETACTIVE(_b, _n) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_b)->current + (_n) <= (_b)->used); \
+ (_b)->active = (_b)->current + (_n); \
} while (0)
-#define ISC__BUFFER_FIRST(_b) \
- do { \
- (_b)->current = 0; \
+#define ISC__BUFFER_FIRST(_b) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ (_b)->current = 0; \
} while (0)
-#define ISC__BUFFER_FORWARD(_b, _n) \
- do { \
- (_b)->current += (_n); \
+#define ISC__BUFFER_FORWARD(_b, _n) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_b)->current + (_n) <= (_b)->used); \
+ (_b)->current += (_n); \
} while (0)
-#define ISC__BUFFER_BACK(_b, _n) \
- do { \
- (_b)->current -= (_n); \
+#define ISC__BUFFER_BACK(_b, _n) \
+ do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_n) <= (_b)->current); \
+ (_b)->current -= (_n); \
} while (0)
#define ISC__BUFFER_PUTMEM(_b, _base, _length) \
do { \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
ISC_REQUIRE(isc_buffer_reserve(&_tmp, _length) == \
do { \
unsigned int _length; \
unsigned char *_cp; \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
+ ISC_REQUIRE((_source) != NULL); \
_length = (unsigned int)strlen(_source); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
unsigned char *_cp; \
/* evaluate (_val) only once */ \
uint8_t _val2 = (_val); \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
ISC_REQUIRE(isc_buffer_reserve(&_tmp, 1) == \
unsigned char *_cp; \
/* evaluate (_val) only once */ \
uint16_t _val2 = (_val); \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
ISC_REQUIRE(isc_buffer_reserve(&_tmp, 2) == \
unsigned char *_cp; \
/* evaluate (_val) only once */ \
uint32_t _val2 = (_val); \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
ISC_REQUIRE(isc_buffer_reserve(&_tmp, 3) == \
unsigned char *_cp; \
/* evaluate (_val) only once */ \
uint32_t _val2 = (_val); \
+ ISC_REQUIRE(ISC_BUFFER_VALID(_b)); \
if (ISC_UNLIKELY((_b)->autore)) { \
isc_buffer_t *_tmp = _b; \
ISC_REQUIRE(isc_buffer_reserve(&_tmp, 4) == \