Re: canvas item color



On Fri, 8 Jan 1999, Todd Graham Lewis wrote:

> > 	char *
> > 	get_color_spec (int r, int g, int b)
> > 	{
> > 		static char spec[50];
> > 	
> > 		sprintf (spec, "#%04x%04x%04x", r, g, b);
> > 		return spec;
> > 	}

> Question from Todd, the notoriously bad C programmer:
> 
> Isn't this a memory leak?  Shouldn't the caller be responsible for
> allocating spec[] and passing it in?

Not a memory leak (the spec[] array is static), but somewhat dangerous in
other ways (threads, re-entrancy, &c).

Matthew.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]