[Rpm-maint] [PATCH] parseSpec: use getline instead of fgetc

Dmitry V. Levin ldv at altlinux.org
Tue Mar 14 20:57:17 UTC 2017


On Mon, Mar 13, 2017 at 07:17:40PM +0300, Gleb Fotengauer-Malinovskiy wrote:
> 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>

Reviewed-by: Dmitry V. Levin <ldv at altlinux.org>

fwiw, we've been using this getline approach in parseSpec
for almost 5 years
(http://git.altlinux.org/gears/r/..git?p=rpm-build.git;a=commitdiff;h=4.0.4-alt100.47-4-g12538e4)
so it has received a very extensive testing.

> ---
>  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);
>  

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20170314/6efadde5/attachment.asc>


More information about the Rpm-maint mailing list