[GRASS5] How to get monitor background color?

Markus Neteler neteler at itc.it
Fri Oct 26 13:20:55 EDT 2001


On Fri, Oct 26, 2001 at 09:48:15AM -0400, Carl Worth wrote:
> Markus Neteler writes:
>  > However, it doesn't work for me (I may be lost again with strings
>  > and pointers):
>  > 
>  > char * colorname;
>  > int bgcolor;
>  > 
>  > bgcolor=D_translate_color(D_get_erase_color(colorname));
> 
> Markus, the code above is broken. You're passing an uninitialized
> pointer (colorname), to D_get_erase_Color. Inside, that function does:
> 
> 	strcpy(colorname, list[0]);
> 
> which is sure to segfault or worse if colorname is not pointing to
> allocated memory.
> 
> Instead, you should first ensure that colorname is pointing to some
> allocated memory large enough to hold the resulting color. Something
> like:
> 
> 	char colorname[MAX_COLOR_LEN];
> 
> I have no idea what value might be appropriate for MAX_COLOR_LEN.
> 
> (And if there isn't a well-defined value for this somewhere, then
> D_get_erase_color should be updated to accept a maximum length as an
> input parameter or to allocate memory for the result itself).
> 

Thanks for the hints, Carl,
however, I am still a bit stuck here. Perhaps our display gurus
have a recommendation?

Thanks,

 Markus



More information about the grass-dev mailing list