Error on unclosed macros & trailing line continuations in spec (RhBug:681567)
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 16 Jun 2011 16:21:54 +0000 (19:21 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 16 Jun 2011 16:30:34 +0000 (19:30 +0300)
- Track the starting line in case copyNextLineFromOFI() indicates
  a multiline-construct. If we get an EOF from readLineFromOFI()
  while inside multiline read, its an illegal construct of some kind
  and we can even spit out a reasonably meaningful error pointing
  out the starting line number of the bad construct.

build/parseSpec.c

index 89f1f40..a1a43d9 100644 (file)
@@ -303,16 +303,26 @@ int readLine(rpmSpec spec, int strip)
     struct ReadLevelEntry *rl;
     OFI_t *ofi = spec->fileStack;
     int rc;
+    int startLine = 0;
 
     if (!restoreFirstChar(spec)) {
     retry:
-       if ((rc = readLineFromOFI(spec, ofi)) != 0)
+       if ((rc = readLineFromOFI(spec, ofi)) != 0) {
+           if (startLine > 0) {
+               rpmlog(RPMLOG_ERR,
+                   _("line %d: unclosed macro or bad line continuation\n"),
+                   startLine);
+               rc = PART_ERROR;
+           }
            return rc;
+       }
        ofi = spec->fileStack;
 
        /* Copy next file line into the spec line buffer */
        rc = copyNextLineFromOFI(spec, ofi);
        if (rc > 0) {
+           if (startLine == 0)
+               startLine = spec->lineNum;
            goto retry;
        } else if (rc < 0) {
            return PART_ERROR;