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.c | |
| 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.c')
| -rw-r--r-- | lib/stream.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/stream.c b/lib/stream.c index 768114e69b..6e62e11380 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -256,6 +256,18 @@ void stream_forward_getp(struct stream *s, size_t size) s->getp += size; } +bool stream_forward_getp2(struct stream *s, size_t size) +{ + STREAM_VERIFY_SANE(s); + + if (!GETP_VALID(s, s->getp + size)) + return false; + + s->getp += size; + + return true; +} + void stream_forward_endp(struct stream *s, size_t size) { STREAM_VERIFY_SANE(s); @@ -268,6 +280,18 @@ void stream_forward_endp(struct stream *s, size_t size) s->endp += size; } +bool stream_forward_endp2(struct stream *s, size_t size) +{ + STREAM_VERIFY_SANE(s); + + if (!ENDP_VALID(s, s->endp + size)) + return false; + + s->endp += size; + + return true; +} + /* Copy from stream to destination. */ bool stream_get2(void *dst, struct stream *s, size_t size) { |
