ref: 944a4bd1141c0d49a834c1d76bc22e0b1926789e
parent: e1d43651bd376d93d51426e0b72f2ec3d674cabc
author: phil9 <[email protected]>
date: Wed Nov 30 11:19:55 EST 2022
prevent overflow of color cache
--- a/color.c
+++ b/color.c
@@ -31,7 +31,7 @@
c = nil;
n = (r << 24) | (g << 16) | (b << 8) | 0xFF;
- for(i = 0; i < ncolors; i++){
+ for(i = 0; i < nelem(cache); i++){
if(cache[i].n == n){
c = cache[i].i;
break;
@@ -42,6 +42,8 @@
cache[ncolors].n = n;
cache[ncolors].i = c;
ncolors++;
+ if(ncolors == nelem(cache))
+ ncolors = 0;
}
return c;
}