[GRASS-dev] [bug #5037] (grass) GRASS 6.3: d.graph segfault

this bug's URL: http://intevation.de/rt/webrt?serial_num=5037
-------------------------------------------------------------------------

Subject: GRASS 6.3: d.graph segfault

Hi,

d.graph segfaults on startup. (GRASS 6.3-cvs only)

in lib/raster/com_proto.c R_RGB_color()

e.g.

G63> d.mon x0
G63> echo "draw 50 50" | d.graph
Segmentation fault

It breaks due to bad translation of the color=black default option.
    int R,G,B,color;

        /* Parse and select color */
        if (opt2->answer != NULL) {
            color = G_str_to_color(opt2->answer, &R, &G, &B);

            if(color == 0)
                G_fatal_error(_("[%s]: No such color"), opt2->answer);

            if(color == 1) {
                R_RGB_color(R, G, B);
                set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
            }
            else /* (color==2) is "none" */
                set_last_color(0, 0, 0, RGBA_COLOR_NONE);
        }

R,G,B is populated and passed to R_RGB_color(). R_RGB_color() is expecting
unsigned char, and segfaults as it thinks int 0 is '\0' ???

(gdb) bt full
#0 0x400a144d in R_RGB_color (red=0 '\0', grn=0 '\0', blu=0 '\0') at
com_proto.c:166
No locals.
#1 0x0804ac65 in main (argc=2, argv=0xbffff6f4) at main.c:81
        window_name =
"\000÷ÿ¿töÿ¿\232;\000@ l\001Aà­\004\b(Æ\004\bxöÿ¿=\221\004\b\234\001\000@Xï\n@\230öÿ¿û­\004\bÀ\210\024A@®\004\bôöÿ¿À\210\024A"
        module = (struct GModule *) 0x4005be50
        opt1 = (struct Option *) 0x4005be00
        opt2 = (struct Option *) 0x804c7d0
        mapcoords = (struct Flag *) 0x4005bdd8
        R = 0
        G = 0
        B = 0
        color = 1

thanks,
Hamish

-------------------------------------------- Managed by Request Tracker

Request Tracker wrote:

this bug's URL: http://intevation.de/rt/webrt?serial_num=5037
-------------------------------------------------------------------------

Subject: GRASS 6.3: d.graph segfault

d.graph segfaults on startup. (GRASS 6.3-cvs only)

in lib/raster/com_proto.c R_RGB_color()

e.g.

G63> d.mon x0
G63> echo "draw 50 50" | d.graph
Segmentation fault

It breaks due to bad translation of the color=black default option.

Incorrect. It segfaults because trans is NULL, because R_RGB_color()
is called before R_open_driver().

R_open_driver() or R__open_quiet() must be called before almost any
other R_* functions are called. The only exceptions are:

  R_parse_monitorcap
  R_set_update_function
  R_call_update_function
  R_has_update_function
  R_set_cancel
  R_get_cancel
  R_pad_freelist
  R_pad_perror

The old library would silently ignore any operations performed while
not connected to a driver.

--
Glynn Clements <glynn@gclements.plus.com>

> this bug's URL: http://intevation.de/rt/webrt?serial_num=5037
> -------------------------------------------------------------------
>
> Subject: GRASS 6.3: d.graph segfault
>
> d.graph segfaults on startup. (GRASS 6.3-cvs only)

..
Glynn:

It segfaults because trans is NULL, because R_RGB_color()
is called before R_open_driver().

R_open_driver() or R__open_quiet() must be called before almost any
other R_* functions are called. The only exceptions are:

  R_parse_monitorcap
  R_set_update_function
  R_call_update_function
  R_has_update_function
  R_set_cancel
  R_get_cancel
  R_pad_freelist
  R_pad_perror

The old library would silently ignore any operations performed while
not connected to a driver.

ok, thanks. It works now.

I have added a new "extra/pentagon" symbol to 6.3-cvs.

e.g.:
echo "symbol extra/pentagon 65 50 50 blue none" | d.graph

Hamish