Skip to content

Commit f616c4f

Browse files
committed
Fix LINE bug added in recent commit.
Clipping case fixed so y1 and y2 are updated, otherwise SET_DIRTY could be passed out-of-bounds values. As it was, y2 could be one too high/low, and y1 was never clipped at all.
1 parent b91483a commit f616c4f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/gfxlib2/gfx_line.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ void fb_GfxDrawLine(FB_GFXCTX *context, int x1, int y1, int x2, int y2, unsigned
134134
y += ay * skip;
135135
d -= skip * dx;
136136
if ((y < ymin) || (y > ymax))
137-
y = y2;
137+
goto done;
138138
} else if (d < (dy - dx)) {
139139
skip = ((dy - dx) - d) / dy + 1;
140140
x += ax * skip;
141141
d += skip * dy;
142142
rot += skip;
143143
if ((x < xmin) || (x > xmax))
144-
x = x2;
144+
goto done;
145145
}
146146
bit = 0x8000 >> (rot & 0xF);
147+
y1 = y; /* first dirty row */
147148

148149
while ((x != x2) && (y != y2)) {
149150
if (style & bit)
@@ -165,16 +166,17 @@ void fb_GfxDrawLine(FB_GFXCTX *context, int x1, int y1, int x2, int y2, unsigned
165166
x += ax * skip;
166167
d += skip * dy;
167168
if ((x < xmin) || (x > xmax))
168-
x = x2;
169+
goto done;
169170
} else if (d > dy - dx) {
170171
skip = (d - (dy - dx)) / dx + 1;
171172
y += ay * skip;
172173
d -= skip * dx;
173174
rot += skip;
174175
if ((y < ymin) || (y > ymax))
175-
y = y2;
176+
goto done;
176177
}
177178
bit = 0x8000 >> (rot & 0xF);
179+
y1 = y; /* first dirty row */
178180

179181
while ((y != y2) && (x != x2)) {
180182
if (style & bit)
@@ -189,10 +191,12 @@ void fb_GfxDrawLine(FB_GFXCTX *context, int x1, int y1, int x2, int y2, unsigned
189191
/* invariant: (-dx) <= d < (-dx + dy) */
190192
}
191193
}
194+
y2 -= ay; /* last dirty row */
192195
}
193196
if (y1 > y2)
194197
SWAP(y1, y2);
195198
SET_DIRTY(context, y1, y2 - y1 + 1);
199+
done:
196200
DRIVER_UNLOCK();
197201
}
198202

0 commit comments

Comments
 (0)