]> sigrok.org Git - libsigrok.git/commitdiff
input/csv: Fix a false negative after successful import
authorGerhard Sittig <redacted>
Mon, 5 Jun 2017 11:37:33 +0000 (13:37 +0200)
committerUwe Hermann <redacted>
Tue, 6 Jun 2017 21:27:52 +0000 (23:27 +0200)
The input module runs receive() and end() invocations which end up
calling process_buffer(). It's perfectly legal to call the process
routine with an empty accumulation buffer, especially when the process
routine was called from end().

This fixes a condition where PulseView raised a fatal error at the end
of a completed successful import.

Reported-By: Sergey Alirzaev <redacted>
src/input/csv.c

index 5585b0eeacc07247aca5a34056d475cbf4c4a298..5399027bf823305ab0a33c79b02ec9783e1ca5c3 100644 (file)
@@ -644,11 +644,18 @@ static int process_buffer(struct sr_input *in)
        else
                max_columns = 1;
 
+       /*
+        * Consider empty input non-fatal. Keep accumulating input until
+        * at least one full text line has become available. Grab the
+        * 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.
+        */
+       if (!in->buf->len)
+               return SR_OK;
        p = g_strrstr_len(in->buf->str, in->buf->len, inc->termination);
        if (!p)
-               /* Don't have a full line. */
                return SR_ERR;
-
        *p = '\0';
        g_strstrip(in->buf->str);