Skip to content

Commit

Permalink
util/streaming: improve error handling
Browse files Browse the repository at this point in the history
It differentiates memory error than regular ones.

(cherry picked from commit 0e70958)
  • Loading branch information
regit authored and inashivb committed Jan 13, 2022
1 parent 2b6c576 commit 36659d1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/util-streaming-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ int StreamingBufferAppendNoTrack(StreamingBuffer *sb,

/**
* \param offset offset relative to StreamingBuffer::stream_offset
*
* \return 0 in case of success
* \return -1 on memory allocation errors
* \return negative value on other errors
*/
int StreamingBufferInsertAt(StreamingBuffer *sb, StreamingBufferSegment *seg,
const uint8_t *data, uint32_t data_len,
Expand All @@ -679,7 +683,7 @@ int StreamingBufferInsertAt(StreamingBuffer *sb, StreamingBufferSegment *seg,
BUG_ON(seg == NULL);

if (offset < sb->stream_offset)
return -1;
return -2;

if (sb->buf == NULL) {
if (InitBuffer(sb) == -1)
Expand All @@ -698,7 +702,7 @@ int StreamingBufferInsertAt(StreamingBuffer *sb, StreamingBufferSegment *seg,
}
}
if (!DATA_FITS_AT_OFFSET(sb, data_len, rel_offset)) {
return -1;
return -2;
}

memcpy(sb->buf + rel_offset, data, data_len);
Expand Down

0 comments on commit 36659d1

Please sign in to comment.