Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libratbox/include/rb_linebuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void rb_linebuf_init(void);
void rb_linebuf_newbuf(rb_buf_head_t *);
void rb_linebuf_donebuf(rb_buf_head_t *);
int rb_linebuf_parse(rb_buf_head_t *, char *, size_t, bool);
ssize_t rb_linebuf_get(rb_buf_head_t * bufhead, char *buf, size_t buflen, bool partial, bool raw);
size_t rb_linebuf_get(rb_buf_head_t * bufhead, char *buf, size_t buflen, bool partial, bool raw);
void rb_linebuf_putmsg(rb_buf_head_t *, const char *, va_list *, const char *, ...);
void rb_linebuf_put(rb_buf_head_t *, const char *, ...);
void rb_linebuf_putbuf(rb_buf_head_t * bufhead, const char *buffer);
Expand Down
10 changes: 6 additions & 4 deletions libratbox/src/linebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ rb_linebuf_parse(rb_buf_head_t * bufhead, char *data, size_t len, bool raw)
* get the next buffer from our line. For the time being it will copy
* data into the given buffer and free the underlying linebuf.
*/
ssize_t
size_t
rb_linebuf_get(rb_buf_head_t * bufhead, char *buf, size_t buflen, bool partial, bool raw)
{
rb_buf_line_t *bufline;
Expand All @@ -450,6 +450,10 @@ rb_linebuf_get(rb_buf_head_t * bufhead, char *buf, size_t buflen, bool partial,
if(bufhead->list.head == NULL)
return 0; /* Obviously not.. hrm. */

/* make sure we have a buffer */
if(buf == NULL || buflen == 0)
return 0;

bufline = bufhead->list.head->data;

/* make sure that the buffer was actually *terminated */
Expand Down Expand Up @@ -490,13 +494,11 @@ rb_linebuf_get(rb_buf_head_t * bufhead, char *buf, size_t buflen, bool partial,
if(raw == false)
buf[cpylen] = '\0';

lrb_assert(cpylen >= 0);

/* Deallocate the line */
rb_linebuf_done_line(bufhead, bufline, bufhead->list.head);

/* return how much we copied */
return (ssize_t)cpylen;
return cpylen;
}

/*
Expand Down