Ivan Shmakov wrote:

>       As of a recent SVN HEAD, `d.legend' uses a static buffer to
>       store the value of the `map' option.  It's therefore impossible
>       to pass raster names more than 63 bytes long to `d.legend'.
>       Since I don't see why a static buffer may be necessary here, I
>       suggest the following (yet untested) patch.
> 
> diff --git a/display/d.legend/main.c b/display/d.legend/main.c
> index d827d04..324012d 100644
> --- a/display/d.legend/main.c
> +++ b/display/d.legend/main.c
> @@ -39,7 +39,7 @@ int main( int argc, char **argv )
>  {
>       char *mapset ;
>       char buff[512];
> -     char map_name[64] ;
> +     const char *map_name;
>       char window_name[64] ;
>       int black ;
>       int cats_num ;
> @@ -188,7 +188,7 @@ int main( int argc, char **argv )
>       if (G_parser(argc, argv))
>               exit(EXIT_FAILURE);
>  
> -     strcpy(map_name, opt1->answer) ;
> +     map_name = opt1->answer;
>  
>          hide_catstr = hidestr->answer;  /* note hide_catstr gets changed and 
> re-read below */
>          hide_catnum = hidenum->answer;
> 
> PS.  I've seen a number of other uses of static buffers scattered across
>       the code, leading to both potential limits and crashes, which
>       I'm on the way to investigate.

There isn't necessarily a problem with using fixed-size buffers for
map names, but the size should be GNAME_MAX. Similar constants exist
for mapset names and pathnames:

        /* File/directory name lengths */
        #define GNAME_MAX 256
        #define GMAPSET_MAX 256

        #define GPATH_MAX 4096

In the specific case of d.legend, your fix is the correct one, except
that map_name needs to be "char *" not "const char *", as
G_find_cell() may modify the map name (it removes any @mapset suffix).

As this never enlarges the string, it's okay to re-use the original
buffer.

-- 
Glynn Clements <[EMAIL PROTECTED]>
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to