fix segfault in check_pixel

This commit is contained in:
Lilith 2023-06-04 00:24:27 +02:00
parent 9e61f3b192
commit 2d7b714c20
Signed by: konomo
GPG Key ID: 3DD7B85531A23133
1 changed files with 9 additions and 7 deletions

View File

@ -54,7 +54,7 @@ int main(void)
unsigned char generate_color()
{
unsigned char clr = rand() % colors;
unsigned char clr = rand() % colors + colors;
clr*=(unsigned char)lround( (256/colors) );
@ -191,6 +191,13 @@ void process(unsigned int id, unsigned int step)
int check_pixel(unsigned int x, unsigned int y)
{
printf("Checking (%u|%u)\n", x, y);
if(x>=WIDTH || y>=HEIGHT)
{
fprintf(stderr, "coords (%d|%d) exceed image size %d×%d.\n", x, y, WIDTH, HEIGHT);
return 1;
}
/* as the image will be grayscaled, it works to check only one layer */
/* this implies the background colour is 0 */
if(image[y][x][0]!=0)
@ -202,12 +209,7 @@ int check_pixel(unsigned int x, unsigned int y)
int paint_pixel(unsigned int x, unsigned int y, unsigned char clr)
{
if(x>WIDTH || y>HEIGHT)
{
fprintf(stderr, "coords (%d|%d) exceed image size %d×%d.\n", x, y, WIDTH, HEIGHT);
return 1;
}
printf("paint_pixel called\n");
if(check_pixel(x, y)) return 1;
image[y][x][0]=clr;