line-reader: handle invalid parameters more gracefully

This silences coverity which doesn't handle return_if_fail() macros
very well.
This commit is contained in:
Christian Hergert
2016-08-22 11:02:03 -07:00
parent 46a257da6e
commit e4e1bf73b3

View File

@ -51,28 +51,22 @@ SpLineReader *
sp_line_reader_new (const gchar *contents, sp_line_reader_new (const gchar *contents,
gssize length) gssize length)
{ {
SpLineReader *self; SpLineReader *self = g_slice_new (SpLineReader);
g_return_val_if_fail (contents != NULL, NULL); if (contents == NULL)
self = g_slice_new (SpLineReader);
if (length < 0)
length = strlen (contents);
if (contents != NULL)
{ {
self->contents = contents; contents = "";
self->length = length; length = 0;
self->pos = 0;
} }
else else if (length < 0)
{ {
self->contents = NULL; length = strlen (contents);
self->length = 0;
self->pos = 0;
} }
self->contents = contents;
self->length = length;
self->pos = 0;
return self; return self;
} }