This breaks the file streaming sbuff, so record the shifted count separately in the fr_sbuff_uctx_file_t structure
if (extension == SIZE_MAX) extension = 0;
- total_read = sbuff->shifted + (sbuff->end - sbuff->buff);
+ total_read = fctx->shifted + (sbuff->end - sbuff->buff);
if (total_read >= fctx->max) {
fr_strerror_const("Can't satisfy extension request, max bytes read");
return 0; /* There's no way we could satisfy the extension request */
*
* Note: p and markers are constraints here.
*/
- fr_sbuff_shift(sbuff, fr_sbuff_used(sbuff));
+ fctx->shifted += fr_sbuff_shift(sbuff, fr_sbuff_used(sbuff));
}
available = fctx->buff_end - sbuff->end;
FILE *file; //!< FILE * we're reading from.
char *buff_end; //!< The true end of the buffer.
size_t max; //!< Maximum number of bytes to read.
+ size_t shifted; //!< How much we've read from this file.
bool eof; //!< are we at EOF?
} fr_sbuff_uctx_file_t;
.p = (_current), \
.is_const = fr_sbuff_ptr(_sbuff_or_marker)->is_const, \
.adv_parent = (_adv_parent), \
- .shifted = fr_sbuff_ptr(_sbuff_or_marker)->shifted, \
+ .shifted = 0, \
.extend = (_extend), \
.uctx = fr_sbuff_ptr(_sbuff_or_marker)->uctx, \
.parent = fr_sbuff_ptr(_sbuff_or_marker) \
TEST_CHECK(fr_sbuff_init_file(&sbuff, &fctx, buff, sizeof(buff), fp, sizeof(fbuff) - 8) == &sbuff);
TEST_CASE("Confirm that max stops us from seeing xyzzy");
- TEST_CHECK_LEN(sizeof(fbuff) - 8, fr_sbuff_adv_past_whitespace(&sbuff, SIZE_MAX, NULL));
- (void) fr_sbuff_out_abstrncpy(NULL, &post_ws, &sbuff, 24);
+ TEST_CHECK_SLEN(fr_sbuff_adv_past_whitespace(&sbuff, SIZE_MAX, NULL), sizeof(fbuff) - 8);
+ TEST_CHECK_SLEN(fr_sbuff_out_abstrncpy(NULL, &post_ws, &sbuff, 24), 0);
TEST_CHECK_STRCMP(post_ws, "");
talloc_free(post_ws);
fclose(fp);