add and use bs_capacityassert
parent
9ddab2153f
commit
3fff3ae6db
@ -0,0 +1,13 @@
|
|||||||
|
#include "parse.h"
|
||||||
|
|
||||||
|
// This function asserts that the caller wants to read n bytes from the stream.
|
||||||
|
// If there is less space available, set the stream to error state.
|
||||||
|
int bs_capacityassert(struct bytestream* bs,size_t capacity) {
|
||||||
|
if (bs->cur>=bs->max || // if EOF or error, return 0
|
||||||
|
bs->max - bs->cur < capacity) { // not EOF but less than that many bytes left
|
||||||
|
bs->cur = 1; // set stream to error state
|
||||||
|
bs->max = 0;
|
||||||
|
return 0; // return failure
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
Loading…
Reference in New Issue