[GRASS5] How to get monitor background color?

Carl Worth cworth at east.isi.edu
Fri Oct 26 09:48:15 EDT 2001

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

	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).


More information about the grass-dev mailing list