We should not first dereference p and afterwards assert that is
was not NULL. Instead do the assert first.
The problem was indicated by cppcheck.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
int buf_pop (circbuf_t * buf, char *dest, unsigned int len)
{
unsigned int i;
int buf_pop (circbuf_t * buf, char *dest, unsigned int len)
{
unsigned int i;
assert (buf != NULL);
assert (dest != NULL);
assert (buf != NULL);
assert (dest != NULL);
/* Cap to number of bytes in buffer */
if (len > buf->size)
len = buf->size;
/* Cap to number of bytes in buffer */
if (len > buf->size)
len = buf->size;
{
/* NOTE: this function allows push to overwrite old data. */
unsigned int i;
{
/* NOTE: this function allows push to overwrite old data. */
unsigned int i;
assert (buf != NULL);
assert (src != NULL);
assert (buf != NULL);
assert (src != NULL);
for (i = 0; i < len; i++) {
*p++ = src[i];
if (p == buf->end) {
for (i = 0; i < len; i++) {
*p++ = src[i];
if (p == buf->end) {