input/csv: Accept absence of last end-of-line termination sequence

On the Windows platform it appears to be popular to _not_ terminate the
very last line in a text file. Which results in an unmet constraint in
the CSV input module and an internal exception in PulseView which aborts
program execution.

Cope with the absence of the text line termination sequence at the very
end of the input stream. Keep all other checks in place, such that only
completely received text lines get processed.

This fixes bug #635.
This commit is contained in:
Gerhard Sittig 2017-06-05 19:00:23 +02:00 committed by Uwe Hermann
parent 4439363aa0
commit 7f4c3a6224
1 changed files with 18 additions and 8 deletions

View File

@ -671,7 +671,7 @@ static int initial_receive(const struct sr_input *in)
return ret;
}
static int process_buffer(struct sr_input *in)
static int process_buffer(struct sr_input *in, gboolean is_eof)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_meta meta;
@ -712,14 +712,24 @@ static int process_buffer(struct sr_input *in)
* maximum amount of accumulated data that consists of full text
* lines, and process what has been received so far, leaving not
* yet complete lines for the next invocation.
*
* Enforce that all previously buffered data gets processed in
* the "EOF" condition. Do not insist in the presence of the
* termination sequence for the last line (may often be missing
* on Windows). A present termination sequence will just result
* in the "execution of an empty line", and does not harm.
*/
if (!in->buf->len)
return SR_OK;
p = g_strrstr_len(in->buf->str, in->buf->len, inc->termination);
if (!p)
return SR_ERR;
*p = '\0';
p += strlen(inc->termination);
if (is_eof) {
p = in->buf->str + in->buf->len;
} else {
p = g_strrstr_len(in->buf->str, in->buf->len, inc->termination);
if (!p)
return SR_ERR;
*p = '\0';
p += strlen(inc->termination);
}
g_strstrip(in->buf->str);
ret = SR_OK;
@ -814,7 +824,7 @@ static int receive(struct sr_input *in, GString *buf)
return SR_OK;
}
ret = process_buffer(in);
ret = process_buffer(in, FALSE);
return ret;
}
@ -825,7 +835,7 @@ static int end(struct sr_input *in)
int ret;
if (in->sdi_ready)
ret = process_buffer(in);
ret = process_buffer(in, TRUE);
else
ret = SR_OK;