Panu Matilainen d56ba0
From eb8aee3f45024fa1e631ac2da5b06f5a9abf16d3 Mon Sep 17 00:00:00 2001
Panu Matilainen d56ba0
Message-Id: <eb8aee3f45024fa1e631ac2da5b06f5a9abf16d3.1619509954.git.pmatilai@redhat.com>
Panu Matilainen d56ba0
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen d56ba0
Date: Tue, 27 Apr 2021 10:51:14 +0300
Panu Matilainen d56ba0
Subject: [PATCH] Revert "Fix logic error in macro file reader"
Panu Matilainen d56ba0
Panu Matilainen d56ba0
This trips over the following comment line in macros.python-srpm,
Panu Matilainen d56ba0
preventing all subsequent macros from loading:
Panu Matilainen d56ba0
Panu Matilainen d56ba0
Temporarily revert to let Python builds continue while looking for
Panu Matilainen d56ba0
proper fix.
Panu Matilainen d56ba0
Panu Matilainen d56ba0
This reverts commit 75275a87cff04da65d3557f2c40ea2b526528c4c.
Panu Matilainen d56ba0
---
Panu Matilainen d56ba0
 rpmio/macro.c | 20 ++++++++++----------
Panu Matilainen d56ba0
 1 file changed, 10 insertions(+), 10 deletions(-)
Panu Matilainen d56ba0
Panu Matilainen d56ba0
diff --git a/rpmio/macro.c b/rpmio/macro.c
Panu Matilainen d56ba0
index 6dfc73336..f2a2335df 100644
Panu Matilainen d56ba0
--- a/rpmio/macro.c
Panu Matilainen d56ba0
+++ b/rpmio/macro.c
Panu Matilainen d56ba0
@@ -209,24 +209,24 @@ findEntry(rpmMacroContext mc, const char *name, size_t namelen, size_t *pos)
Panu Matilainen d56ba0
 static int
Panu Matilainen d56ba0
 rdcl(char * buf, size_t size, FILE *f)
Panu Matilainen d56ba0
 {
Panu Matilainen d56ba0
+    char *q = buf - 1;		/* initialize just before buffer. */
Panu Matilainen d56ba0
     size_t nb = 0;
Panu Matilainen d56ba0
+    size_t nread = 0;
Panu Matilainen d56ba0
     int pc = 0, bc = 0, xc = 0;
Panu Matilainen d56ba0
     int nlines = 0;
Panu Matilainen d56ba0
     char *p = buf;
Panu Matilainen d56ba0
-    char *q = buf;
Panu Matilainen d56ba0
 
Panu Matilainen d56ba0
     if (f != NULL)
Panu Matilainen d56ba0
     do {
Panu Matilainen d56ba0
-	*q = '\0';			/* terminate */
Panu Matilainen d56ba0
+	*(++q) = '\0';			/* terminate and move forward. */
Panu Matilainen d56ba0
 	if (fgets(q, size, f) == NULL)	/* read next line. */
Panu Matilainen d56ba0
 	    break;
Panu Matilainen d56ba0
 	nlines++;
Panu Matilainen d56ba0
 	nb = strlen(q);
Panu Matilainen d56ba0
-	for (q += nb; nb > 0 && iseol(q[-1]); q--)
Panu Matilainen d56ba0
+	nread += nb;			/* trim trailing \r and \n */
Panu Matilainen d56ba0
+	for (q += nb - 1; nb > 0 && iseol(*q); q--)
Panu Matilainen d56ba0
 	    nb--;
Panu Matilainen d56ba0
-	if (*q == 0)
Panu Matilainen d56ba0
-	    break;			/* no newline found, EOF */
Panu Matilainen d56ba0
-	for (; p < q; p++) {
Panu Matilainen d56ba0
+	for (; p <= q; p++) {
Panu Matilainen d56ba0
 	    switch (*p) {
Panu Matilainen d56ba0
 		case '\\':
Panu Matilainen d56ba0
 		    switch (*(p+1)) {
Panu Matilainen d56ba0
@@ -250,14 +250,14 @@ rdcl(char * buf, size_t size, FILE *f)
Panu Matilainen d56ba0
 		case ']': if (xc > 0) xc--; break;
Panu Matilainen d56ba0
 	    }
Panu Matilainen d56ba0
 	}
Panu Matilainen d56ba0
-	if ((nb == 0 || q[-1] != '\\') && !bc && !pc && !xc) {
Panu Matilainen d56ba0
-	    *q = '\0';		/* trim trailing \r, \n */
Panu Matilainen d56ba0
+	if (nb == 0 || (*q != '\\' && !bc && !pc && !xc) || *(q+1) == '\0') {
Panu Matilainen d56ba0
+	    *(++q) = '\0';		/* trim trailing \r, \n */
Panu Matilainen d56ba0
 	    break;
Panu Matilainen d56ba0
 	}
Panu Matilainen d56ba0
 	q++; nb++;			/* copy newline too */
Panu Matilainen d56ba0
 	size -= nb;
Panu Matilainen d56ba0
-	if (q[-1] == '\r')			/* XXX avoid \r madness */
Panu Matilainen d56ba0
-	    q[-1] = '\n';
Panu Matilainen d56ba0
+	if (*q == '\r')			/* XXX avoid \r madness */
Panu Matilainen d56ba0
+	    *q = '\n';
Panu Matilainen d56ba0
     } while (size > 0);
Panu Matilainen d56ba0
     return nlines;
Panu Matilainen d56ba0
 }
Panu Matilainen d56ba0
-- 
Panu Matilainen d56ba0
2.30.2
Panu Matilainen d56ba0