[pacman-dev] [PATCH] Size handling was changed in fgets() functions
Jeff
jeff at kcaccess.com
Sun Sep 20 10:28:34 EDT 2009
On Sun, Sep 20, 2009 at 11:21:19PM +1000, Allan McRae wrote:
> Laszlo Papp 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?
If the size of line is ever changed, every single instance of the
hardcoded number has to be changed which can be error prone. Buffer
overruns are a real possibility. While this gains you nothing if line is
*never* changed, it is best practice to not hardcode any value which is
used in multiple places.
--
Jeff
My other computer is an abacus.
More information about the pacman-dev
mailing list