]> granicus.if.org Git - graphviz/commitdiff
fix line numbers in GVPR error reporting
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 12 Jul 2020 17:32:55 +0000 (10:32 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 12 Jul 2020 20:36:39 +0000 (13:36 -0700)
When swallowing a single line comment (C-style "//..." or shell-style "#..."),
lib/gvpr would push the trailing newline into its output buffer as well as
yielding it. The effect of this was that the second stage parsing done by
lib/expr would see two newlines, throwing off its recorded line number by one
for each single line comment. Fixes #1594.

CHANGELOG.md
lib/gvpr/parse.c
rtest/1594.gvpr [new file with mode: 0644]
rtest/test_regression.py

index ef60933b0f046898da7c7afb5fa317c96efa0157..f293b7ed10a2126c338d3cbf2d5a3949caa4593c 100644 (file)
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+- gvpr: line numbers in gvpr errors/warnings are incorrect #1594
+
 ## [2.44.1] - 2020-06-29
 
 ### Added
index 376dd1c71a483c895b381b81da68e5a9bb8924a7..8b7cdf4e3a6ccc2e460af8e9dfaa853d97769156 100644 (file)
@@ -52,7 +52,7 @@ static char *caseStr(case_t cs)
 /* eol:
  * Eat characters until eol.
  */
-static int eol (Sfio_t * str, Sfio_t * ostr)
+static int eol (Sfio_t * str)
 {
     int c;
     while ((c = sfgetc(str)) != '\n') {
@@ -61,8 +61,6 @@ static int eol (Sfio_t * str, Sfio_t * ostr)
     }
     lineno++;
     col0 = 1;
-    if (ostr)
-       sfputc(ostr, c);
     return c;
 }
 
@@ -85,7 +83,7 @@ static int readc(Sfio_t * str, Sfio_t * ostr)
        break;
     case '#':
        if (col0) { /* shell comment */
-           c = eol (str, ostr);
+           c = eol (str);
        }
        else col0 = 0;
        break;
@@ -122,7 +120,7 @@ static int readc(Sfio_t * str, Sfio_t * ostr)
            }
            break;
        case '/':               /* in C++ comment */
-           c = eol (str, ostr);
+           c = eol (str);
            break;
        default:                /* not a comment  */
            if (cc >= '\0')
diff --git a/rtest/1594.gvpr b/rtest/1594.gvpr
new file mode 100644 (file)
index 0000000..d6f6c06
--- /dev/null
@@ -0,0 +1,4 @@
+BEGIN {
+  // a comment
+  0p0p0
+}
index 614b92c6b476c9ff39422c204a1bc2ea7f2077ad..04d8f6a156d2678a30a593013e3a813c8dfaace5 100644 (file)
@@ -63,3 +63,22 @@ def test_1449():
     assert p.returncode == 0, 'Graphviz exited with non-zero status'
 
     assert stderr.strip() == '', 'SVG color scheme use caused warnings'
+
+def test_1594():
+    '''
+    GVPR should give accurate line numbers in error messages
+    https://gitlab.com/graphviz/graphviz/-/issues/1594
+    '''
+
+    # locate our associated test case in this directory
+    input = os.path.join(os.path.dirname(__file__), '1594.gvpr')
+
+    # run GVPR with our (malformed) input program
+    p = subprocess.Popen(['gvpr', '-f', input], stdin=subprocess.PIPE,
+      stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+    _, stderr = p.communicate()
+
+    assert p.returncode != 0, 'GVPR did not reject malformed program'
+
+    assert 'line 3:' in stderr, \
+      'GVPR did not identify correct line of syntax error'