/*
* Clear out the existing data
*/
- fr_sbuff_shift(&sbuff, fr_sbuff_used(&m_start));
+ fr_sbuff_shift(&sbuff, fr_sbuff_used(&m_start), false);
}
}
/*
* Clear out printed data
*/
- fr_sbuff_shift(&lb->sbuff, fr_sbuff_used(&lb->logged_m));
+ fr_sbuff_shift(&lb->sbuff, fr_sbuff_used(&lb->logged_m), false);
return len; /* Amount of data written */
}
/*
* Clear out printed data
*/
- fr_sbuff_shift(&lb->sbuff, fr_sbuff_used(&lb->logged_m));
+ fr_sbuff_shift(&lb->sbuff, fr_sbuff_used(&lb->logged_m), false);
return len; /* Amount of data written */
}
/*
* Clear out the existing data
*/
- fr_sbuff_shift(&sbuff, fr_sbuff_used(&m_start));
+ fr_sbuff_shift(&sbuff, fr_sbuff_used(&m_start), false);
}
}
* @param[in] sbuff to shift.
* @param[in] shift the contents of the buffer this many bytes
* towards the start of the buffer.
+ * @param[in] move_end If the buffer is used for reading, then this should be true
+ * so we cannot read passed the end of valid data.
* @return
* - 0 the shift failed due to constraining pointers.
* - >0 the number of bytes we managed to shift pointers
* existing contents of the buffer, and fill the free
* space at the end of the buffer with additional data.
*/
-size_t fr_sbuff_shift(fr_sbuff_t *sbuff, size_t shift)
+size_t fr_sbuff_shift(fr_sbuff_t *sbuff, size_t shift, bool move_end)
{
fr_sbuff_t *sbuff_i;
char *buff, *end; /* Current start */
sbuff_i->start -= min(max_shift, sbuff_i->start - buff);
sbuff_i->p -= max_shift;
- sbuff_i->end -= max_shift;
+ if (move_end) sbuff_i->end -= max_shift;
sbuff_i->shifted += (max_shift - (start - sbuff_i->start));
for (m_i = sbuff_i->m; m_i; m_i = m_i->next) m_i->p -= max_shift;
}
*
* Note: p and markers are constraints here.
*/
- fctx->shifted += fr_sbuff_shift(sbuff, shift);
+ fctx->shifted += fr_sbuff_shift(sbuff, shift, true);
}
available = fctx->buff_end - sbuff->end;
void fr_sbuff_update(fr_sbuff_t *sbuff, char *new_buff, size_t new_len);
-size_t fr_sbuff_shift(fr_sbuff_t *sbuff, size_t shift);
+size_t fr_sbuff_shift(fr_sbuff_t *sbuff, size_t shift, bool move_end);
size_t fr_sbuff_extend_file(fr_sbuff_extend_status_t *status, fr_sbuff_t *sbuff, size_t extension);
TEST_CHECK(fr_sbuff_init_talloc(NULL, &sbuff, &tctx, 4, 8) == &sbuff);
TEST_CHECK(fr_sbuff_in_strcpy(&sbuff, "0123") == 4);
TEST_CHECK(fr_sbuff_in_strcpy(&sbuff, "5678") == 4);
- TEST_CHECK(fr_sbuff_shift(&sbuff, 4) == 4);
+ TEST_CHECK(fr_sbuff_shift(&sbuff, 4, false) == 4);
TEST_CHECK(fr_sbuff_in_strcpy(&sbuff, "AAAA") == 4);
- TEST_CHECK(fr_sbuff_shift(&sbuff, 8) == 8);
+ TEST_CHECK(fr_sbuff_shift(&sbuff, 8, false) == 8);
TEST_CHECK(fr_sbuff_in_strcpy(&sbuff, "BBBBBBBB") == 8);
talloc_free(sbuff.buff);
/*
* Remove the century from the year
*/
- fr_sbuff_shift(&time_sbuff, 2);
+ fr_sbuff_shift(&time_sbuff, 2, false);
/*
* Trim the time string of any unwanted characters