Skip to content

Commit b452b2b

Browse files
committed
Fix infinite loop with zero radius ellipse
1 parent 87859ad commit b452b2b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/hagl_ellipse.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2018-2023 Mika Tuupola
5+
Copyright (c) 2018-2026 Mika Tuupola
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -45,6 +45,12 @@ hagl_draw_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_
4545
int32_t asq = a * a;
4646
int32_t bsq = b * b;
4747

48+
/* Zero radius ellipse should output a single pixel */
49+
if (0 == a && 0 == b) {
50+
hagl_put_pixel(surface, x0, y0, color);
51+
return;
52+
}
53+
4854
hagl_put_pixel(surface, x0, y0 + b, color);
4955
hagl_put_pixel(surface, x0, y0 - b, color);
5056

@@ -118,6 +124,12 @@ hagl_fill_ellipse(void const *surface, int16_t x0, int16_t y0, int16_t a, int16_
118124
int32_t asq = a * a;
119125
int32_t bsq = b * b;
120126

127+
/* Zero radius ellipse should output a single pixel */
128+
if (0 == a && 0 == b) {
129+
hagl_put_pixel(surface, x0, y0, color);
130+
return;
131+
}
132+
121133
hagl_put_pixel(surface, x0, y0 + b, color);
122134
hagl_put_pixel(surface, x0, y0 - b, color);
123135

0 commit comments

Comments
 (0)