[augeas-devel] Make a file-scoped static array "const"

David Lutterkort dlutter at redhat.com
Tue May 20 19:49:12 UTC 2008


On Tue, 2008-05-20 at 21:23 +0200, Jim Meyering wrote:
> changeset:   480:2212572bc990
> tag:         tip
> user:        Jim Meyering <meyering at redhat.com>
> date:        Sun May 18 11:22:05 2008 +0200
> files:       src/augtool.c
> description:
> Make a file-scoped static array "const".
> 
> * src/augtool.c [commands]: Make this variable "const".
> (cmd_help, run_command): Make index pointers const, too.

ACK, except for:

> diff --git a/src/augtool.c b/src/augtool.c
> --- a/src/augtool.c
> +++ b/src/augtool.c
> @@ -37,7 +37,7 @@
>      const char *help;
>  };

>  static char *cleanpath(char *path) {
> -    if (strlen(path) == 0)
> -        return path;
>      char *e = path + strlen(path) - 1;
>      while (e != path && (*e == SEP || isspace(*e)))
>          *e-- = '\0';
> @@ -231,7 +229,7 @@
>  }

This will lead to e == path - 1  if path is the empty string, and the
while loop will write over random memory.

David





More information about the augeas-devel mailing list