diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-05-13 19:10:39 -0400 |
|---|---|---|
| committer | Anuradha Karuppiah <anuradhak@cumulusnetworks.com> | 2020-08-15 08:24:54 -0700 |
| commit | 4adddf0a29910ca68eb241ed7441cf237e9e4cd5 (patch) | |
| tree | 04b79f41b3f98816d414192c5a3c9722bb92ac75 /lib/stream.h | |
| parent | 93b35ca9f83b17e70d9e0dc5a3e879cd38f48179 (diff) | |
lib: add STREAM_FORWARD_[GET|ENDP]
Safe stream macros for adjusting buffer pointers
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/stream.h')
| -rw-r--r-- | lib/stream.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/stream.h b/lib/stream.h index 1250b6944d..f2c16b3486 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -173,7 +173,9 @@ extern struct stream *stream_dupcat(const struct stream *s1, extern void stream_set_getp(struct stream *, size_t); extern void stream_set_endp(struct stream *, size_t); extern void stream_forward_getp(struct stream *, size_t); +extern bool stream_forward_getp2(struct stream *, size_t); extern void stream_forward_endp(struct stream *, size_t); +extern bool stream_forward_endp2(struct stream *, size_t); /* steam_put: NULL source zeroes out size_t bytes of stream */ extern void stream_put(struct stream *, const void *, size_t); @@ -453,6 +455,18 @@ static inline const uint8_t *ptr_get_be32(const uint8_t *ptr, uint32_t *out) goto stream_failure; \ } while (0) +#define STREAM_FORWARD_GETP(STR, SIZE) \ + do { \ + if (!stream_forward_getp2((STR), (SIZE))) \ + goto stream_failure; \ + } while (0) + +#define STREAM_FORWARD_ENDP(STR, SIZE) \ + do { \ + if (!stream_forward_endp2((STR), (SIZE))) \ + goto stream_failure; \ + } while (0) + #ifdef __cplusplus } #endif |
