[pacman-dev] [PATCH] Size handling was changed in fgets() functions

Sebastian Nowicki sebnow at gmail.com
Mon Sep 21 17:27:40 EDT 2009


On Sep 20, 2009, at 3:21 PM, Allan McRae wrote:

>> <snip>
>> diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
>> index c99f596..c182510 100644
>> --- a/lib/libalpm/trans.c
>> +++ b/lib/libalpm/trans.c
>> @@ -320,7 +320,7 @@ static int grep(const char *fn, const char  
>> *needle)
>> 	}
>> 	while(!feof(fp)) {
>> 		char line[1024];
>> -		fgets(line, 1024, fp);
>> +		fgets(line, sizeof(line), fp);
>> 		if(feof(fp)) {
>> 			continue;
>> 		}
>
> This highlights my concerns.  We are removing a known size and  
> instead recalculating it.  What is the advantage of this?

It's a compile-time calculation, so there's really no disadvantage.  
It's just safe programming, as Jeff pointed out. The commit message  
isn't very clear though.


More information about the pacman-dev mailing list