[Rpm-maint] [PATCH] parseSpec: use getline instead of fgetc
Gleb Fotengauer-Malinovskiy
glebfm at altlinux.org
Mon Mar 13 16:17:40 UTC 2017
Replace home-grown buggy imitation of getline(3) with use of getline(3).
Fixes: 92a8babf1b46 ("Remove hopefully the last static buffer in rpm spec reading")
Closes: https://github.com/rpm-software-management/rpm/issues/175
Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm at altlinux.org>
---
build/parseSpec.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/build/parseSpec.c b/build/parseSpec.c
index 20c4555..2928e85 100644
--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -32,7 +32,7 @@ typedef struct OpenFileInfo {
FILE *fp;
int lineNum;
char *readBuf;
- int readBufLen;
+ size_t readBufLen;
const char * readPtr;
struct OpenFileInfo * next;
} OFI_t;
@@ -323,22 +323,7 @@ retry:
/* Make sure we have something in the read buffer */
if (!(ofi->readPtr && *(ofi->readPtr))) {
- int c;
- int i = 0;
-
- while ((c = fgetc(ofi->fp)) != EOF) {
- if (i >= ofi->readBufLen - 1) {
- ofi->readBufLen += BUFSIZ;
- ofi->readBuf = xrealloc(ofi->readBuf, ofi->readBufLen);
- }
- ofi->readBuf[i++] = c;
- if (c == '\n') {
- ofi->readBuf[i] = '\0';
- break;
- }
- }
-
- if (!i) {
+ if (getline(&ofi->readBuf, &ofi->readBufLen, ofi->fp) <= 0) {
/* EOF, remove this file from the stack */
ofi = popOFI(spec);
--
glebfm
More information about the Rpm-maint
mailing list