X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=utils%2Fcolors.c;h=698bc9402fbeeec33d63570a0c6d240f2b645355;hp=93366b64cff46c1c02962df2ce58ee788b91db1a;hb=551b3de3f619c04c2dd1971ee9b3f02e270c28c9;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0 diff --git a/utils/colors.c b/utils/colors.c index 93366b64..698bc940 100644 --- a/utils/colors.c +++ b/utils/colors.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1997 Jamie Zawinski +/* xscreensaver, Copyright (c) 1997 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -25,11 +25,15 @@ void free_colors(Display *dpy, Colormap cmap, XColor *colors, int ncolors) { int i; - unsigned long *pixels = (unsigned long *) malloc(sizeof(*pixels) * ncolors); - for (i = 0; i < ncolors; i++) - pixels[i] = colors[i].pixel; - XFreeColors (dpy, cmap, pixels, ncolors, 0L); - free(pixels); + if (ncolors > 0) + { + unsigned long *pixels = (unsigned long *) + malloc(sizeof(*pixels) * ncolors); + for (i = 0; i < ncolors; i++) + pixels[i] = colors[i].pixel; + XFreeColors (dpy, cmap, pixels, ncolors, 0L); + free(pixels); + } } @@ -46,7 +50,7 @@ allocate_writable_colors (Display *dpy, Colormap cmap, while (got < desired && requested > 0) { - if (desired - got > requested) + if (desired - got < requested) requested = desired - got; if (XAllocColorCells (dpy, cmap, False, 0, 0, new_pixels, requested)) @@ -490,7 +494,7 @@ make_smooth_colormap (Display *dpy, Visual *visual, Colormap cmap, if (dh < 0) dh = -dh; if (dh > 0.5) dh = 0.5 - (dh - 0.5); distance = sqrt ((dh * dh) + - ((s[j] - s[i]) * (s[j] - v[i])) + + ((s[j] - s[i]) * (s[j] - s[i])) + ((v[j] - v[i]) * (v[j] - v[i]))); if (distance < 0.2) goto REPICK_THIS_COLOR; @@ -556,7 +560,8 @@ make_uniform_colormap (Display *dpy, Visual *visual, Colormap cmap, 0, S, V, 359, S, V, colors, &ncolors, - False, True, wanted_writable); + False, True, + (writable_pP && *writable_pP)); /* If we tried for writable cells and got none, try for non-writable. */ if (allocate_p && *ncolorsP == 0 && writable_pP && *writable_pP)