This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [3/8] Fix premature post-increment in collect2.c


Richard Sandiford <richards@transitive.com> writes:

> 	* collect2.c (ignore_library): Avoid premature post-increment
> 	and null deference.
>
> Index: gcc/collect2.c
> ===================================================================
> --- gcc/collect2.c	2009-06-02 13:05:46.000000000 +0100
> +++ gcc/collect2.c	2009-06-02 13:06:04.000000000 +0100
> @@ -2444,8 +2444,9 @@ static int ignore_library (const char *)
>  ignore_library (const char *name)
>  {
>    const char *const *p = &aix_std_libs[0];
> -  while (*p++ != NULL)
> -    if (! strcmp (name, *p)) return 1;
> +  while (*p)
> +    if (! strcmp (name, *p++))
> +      return 1;

Burying the postincrement in the argument to a function call doesn't
seem like a big step forward in clarity.  I would write something more
like

  const char *const *p;
  for (p = &aix_std_libs[0]; *p != NULL; ++p)
    if (strcmp (name, *p) == 0)
      return 1;

I won't insist on that change.  This is OK either way.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]