Skip to content

Commit 545945c

Browse files
committed
Eliminate warnings reported by Cppcheck
1 parent 3d80857 commit 545945c

File tree

6 files changed

+47
-74
lines changed

6 files changed

+47
-74
lines changed

src/fixed.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212

1313
twin_fixed_t twin_fixed_sqrt(twin_fixed_t a)
1414
{
15-
twin_fixed_t max, min, mid;
16-
twin_fixed_t sqr;
15+
twin_fixed_t max = a, min = 0;
1716

18-
max = a;
19-
min = 0;
2017
while (max > min) {
21-
mid = (max + min) >> 1;
18+
twin_fixed_t mid = (max + min) >> 1;
2219
if (mid >= 181 * TWIN_FIXED_ONE) {
2320
max = mid - 1;
2421
continue;
2522
}
26-
sqr = twin_fixed_mul(mid, mid);
23+
twin_fixed_t sqr = twin_fixed_mul(mid, mid);
2724
if (sqr == a)
2825
return mid;
2926
if (sqr < a)
@@ -36,13 +33,12 @@ twin_fixed_t twin_fixed_sqrt(twin_fixed_t a)
3633

3734
twin_sfixed_t _twin_sfixed_sqrt(twin_sfixed_t as)
3835
{
39-
twin_dfixed_t max = as, min = 0, mid;
36+
twin_dfixed_t max = as, min = 0;
4037
twin_dfixed_t a = twin_sfixed_to_dfixed(as);
41-
twin_dfixed_t sqr;
4238

4339
while (max > min) {
44-
mid = (max + min) >> 1;
45-
sqr = mid * mid;
40+
twin_dfixed_t mid = (max + min) >> 1;
41+
twin_dfixed_t sqr = mid * mid;
4642
if (sqr == a)
4743
return (twin_sfixed_t) mid;
4844
if (sqr < a)

src/font.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ void twin_path_ucs4(twin_path_t *path, twin_ucs4_t ucs4)
330330
twin_path_t *pen = NULL;
331331
twin_fixed_t width;
332332
twin_text_info_t info;
333-
signed char op;
334333

335334
_twin_text_compute_info(path, font, &info);
336335
if (info.snap)
@@ -346,6 +345,7 @@ void twin_path_ucs4(twin_path_t *path, twin_ucs4_t ucs4)
346345

347346
x1 = y1 = 0;
348347
for (;;) {
348+
signed char op;
349349
switch ((op = *g++)) {
350350
case 'm':
351351
x1 = FX(*g++, &info);

src/hull.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* All rights reserved.
55
*/
66

7+
#include <stdbool.h>
78
#include <stdlib.h>
89

910
#include "twin_private.h"
@@ -16,7 +17,7 @@ typedef struct twin_slope {
1617
typedef struct _twin_hull {
1718
twin_spoint_t point;
1819
twin_slope_t slope;
19-
int discard;
20+
bool discard;
2021
} twin_hull_t;
2122

2223
static void _twin_slope_init(twin_slope_t *slope,
@@ -29,23 +30,21 @@ static void _twin_slope_init(twin_slope_t *slope,
2930

3031
static twin_hull_t *_twin_hull_create(twin_path_t *path, int *nhull)
3132
{
32-
int i, j;
3333
int n = path->npoints;
3434
twin_spoint_t *p = path->points;
3535
twin_hull_t *hull;
36-
int e;
3736

38-
e = 0;
39-
for (i = 1; i < n; i++)
37+
int e = 0;
38+
for (int i = 1; i < n; i++)
4039
if (p[i].y < p[e].y || (p[i].y == p[e].y && p[i].x < p[e].x))
4140
e = i;
4241

4342
hull = malloc(n * sizeof(twin_hull_t));
44-
if (hull == NULL)
43+
if (!hull)
4544
return NULL;
4645
*nhull = n;
4746

48-
for (i = 0; i < n; i++) {
47+
for (int i = 0, j; i < n; i++) {
4948
/* place extremum first in array */
5049
if (i == 0)
5150
j = e;
@@ -59,9 +58,9 @@ static twin_hull_t *_twin_hull_create(twin_path_t *path, int *nhull)
5958

6059
/* Discard all points coincident with the extremal point */
6160
if (i != 0 && hull[i].slope.dx == 0 && hull[i].slope.dy == 0)
62-
hull[i].discard = 1;
61+
hull[i].discard = true;
6362
else
64-
hull[i].discard = 0;
63+
hull[i].discard = false;
6564
}
6665

6766
return hull;
@@ -102,9 +101,8 @@ static int _twin_hull_vertex_compare(const void *av, const void *bv)
102101
{
103102
twin_hull_t *a = (twin_hull_t *) av;
104103
twin_hull_t *b = (twin_hull_t *) bv;
105-
int ret;
106104

107-
ret = _twin_slope_compare(&a->slope, &b->slope);
105+
int ret = _twin_slope_compare(&a->slope, &b->slope);
108106

109107
/* In the case of two vertices with identical slope from the
110108
extremal point discard the nearer point. */
@@ -116,10 +114,10 @@ static int _twin_hull_vertex_compare(const void *av, const void *bv)
116114
b_dist = ((twin_dfixed_t) b->slope.dx * b->slope.dx +
117115
(twin_dfixed_t) b->slope.dy * b->slope.dy);
118116
if (a_dist < b_dist) {
119-
a->discard = 1;
117+
a->discard = true;
120118
ret = -1;
121119
} else {
122-
b->discard = 1;
120+
b->discard = true;
123121
ret = 1;
124122
}
125123
}
@@ -154,12 +152,11 @@ static int _twin_hull_next_valid(twin_hull_t *hull, int num_hull, int index)
154152

155153
static void _twin_hull_eliminate_concave(twin_hull_t *hull, int num_hull)
156154
{
157-
int i, j, k;
158155
twin_slope_t slope_ij, slope_jk;
159156

160-
i = 0;
161-
j = _twin_hull_next_valid(hull, num_hull, i);
162-
k = _twin_hull_next_valid(hull, num_hull, j);
157+
int i = 0;
158+
int j = _twin_hull_next_valid(hull, num_hull, i);
159+
int k = _twin_hull_next_valid(hull, num_hull, j);
163160

164161
do {
165162
_twin_slope_init(&slope_ij, &hull[i].point, &hull[j].point);
@@ -169,7 +166,7 @@ static void _twin_hull_eliminate_concave(twin_hull_t *hull, int num_hull)
169166
if (_twin_slope_compare(&slope_ij, &slope_jk) >= 0) {
170167
if (i == k)
171168
break;
172-
hull[j].discard = 1;
169+
hull[j].discard = true;
173170
j = i;
174171
i = _twin_hull_prev_valid(hull, num_hull, j);
175172
} else {

src/path.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,42 +193,34 @@ void twin_path_arc(twin_path_t *path,
193193
twin_angle_t extent)
194194
{
195195
twin_matrix_t save = twin_path_current_matrix(path);
196-
twin_fixed_t max_radius;
197-
int32_t sides;
198-
int32_t n;
199-
twin_angle_t a;
200-
twin_angle_t first, last, step, inc;
201-
twin_angle_t epsilon;
202196

203197
twin_path_translate(path, x, y);
204198
twin_path_scale(path, x_radius, y_radius);
205199

206-
max_radius = _twin_matrix_max_radius(&path->state.matrix);
207-
sides = max_radius / twin_sfixed_to_fixed(TWIN_SFIXED_TOLERANCE);
200+
twin_fixed_t max_radius = _twin_matrix_max_radius(&path->state.matrix);
201+
int32_t sides = max_radius / twin_sfixed_to_fixed(TWIN_SFIXED_TOLERANCE);
208202
if (sides > 1024)
209203
sides = 1024;
210204

211-
n = 2;
205+
int32_t n = 2;
212206
while ((1 << n) < sides)
213207
n++;
214208

215-
sides = (1 << n);
216-
217-
step = TWIN_ANGLE_360 >> n;
218-
inc = step;
219-
epsilon = 1;
209+
twin_angle_t step = TWIN_ANGLE_360 >> n;
210+
twin_angle_t inc = step;
211+
twin_angle_t epsilon = 1;
220212
if (extent < 0) {
221213
inc = -inc;
222214
epsilon = -1;
223215
}
224216

225-
first = (start + inc - epsilon) & ~(step - 1);
226-
last = (start + extent - inc + epsilon) & ~(step - 1);
217+
twin_angle_t first = (start + inc - epsilon) & ~(step - 1);
218+
twin_angle_t last = (start + extent - inc + epsilon) & ~(step - 1);
227219

228220
if (first != start)
229221
twin_path_draw(path, twin_cos(start), twin_sin(start));
230222

231-
for (a = first; a != last; a += inc)
223+
for (twin_angle_t a = first; a != last; a += inc)
232224
twin_path_draw(path, twin_cos(a), twin_sin(a));
233225

234226
if (last != start + extent)

src/poly.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@ static int _twin_edge_build(twin_spoint_t *vertices,
6464
twin_sfixed_t dy,
6565
twin_sfixed_t top_y)
6666
{
67-
int v, nv;
6867
int tv, bv;
69-
int e;
70-
twin_sfixed_t y;
7168

72-
e = 0;
73-
for (v = 0; v < nvertices; v++) {
74-
nv = v + 1;
69+
int e = 0;
70+
for (int v = 0; v < nvertices; v++) {
71+
int nv = v + 1;
7572
if (nv == nvertices)
7673
nv = 0;
7774

@@ -91,7 +88,7 @@ static int _twin_edge_build(twin_spoint_t *vertices,
9188
}
9289

9390
/* snap top to first grid point in pixmap */
94-
y = _twin_sfixed_grid_ceil(vertices[tv].y + dy);
91+
twin_sfixed_t y = _twin_sfixed_grid_ceil(vertices[tv].y + dy);
9592
if (y < TWIN_POLY_START + top_y)
9693
y = TWIN_POLY_START + top_y;
9794

@@ -233,14 +230,11 @@ static void _twin_edge_fill(twin_pixmap_t *pixmap,
233230
int nedges)
234231
{
235232
twin_edge_t *active, *a, *n, **prev;
236-
int e;
237-
twin_sfixed_t y;
238233
twin_sfixed_t x0 = 0;
239-
int w;
240234

241235
qsort(edges, nedges, sizeof(twin_edge_t), _edge_compare_y);
242-
e = 0;
243-
y = edges[0].top;
236+
int e = 0;
237+
twin_sfixed_t y = edges[0].top;
244238
active = 0;
245239
for (;;) {
246240
/* add in new edges */
@@ -253,14 +247,13 @@ static void _twin_edge_fill(twin_pixmap_t *pixmap,
253247
}
254248

255249
/* walk this y value marking coverage */
256-
w = 0;
250+
int w = 0;
257251
for (a = active; a; a = a->next) {
258252
if (w == 0)
259253
x0 = a->x;
260254
w += a->winding;
261-
if (w == 0) {
255+
if (w == 0)
262256
_span_fill(pixmap, y, x0, a->x);
263-
}
264257
}
265258

266259
/* step down, clipping to pixmap */
@@ -303,19 +296,14 @@ void twin_fill_path(twin_pixmap_t *pixmap,
303296
twin_coord_t dx,
304297
twin_coord_t dy)
305298
{
306-
twin_edge_t *edges;
307-
int nedges, n;
308-
int nalloc;
309-
int s;
310-
int p;
311299
twin_sfixed_t sdx = twin_int_to_sfixed(dx + pixmap->origin_x);
312300
twin_sfixed_t sdy = twin_int_to_sfixed(dy + pixmap->origin_y);
313301

314-
nalloc = path->npoints + path->nsublen + 1;
315-
edges = malloc(sizeof(twin_edge_t) * nalloc);
316-
p = 0;
317-
nedges = 0;
318-
for (s = 0; s <= path->nsublen; s++) {
302+
int nalloc = path->npoints + path->nsublen + 1;
303+
twin_edge_t *edges = malloc(sizeof(twin_edge_t) * nalloc);
304+
int p = 0;
305+
int nedges = 0;
306+
for (int s = 0; s <= path->nsublen; s++) {
319307
int sublen;
320308
int npoints;
321309

@@ -325,7 +313,8 @@ void twin_fill_path(twin_pixmap_t *pixmap,
325313
sublen = path->sublen[s];
326314
npoints = sublen - p;
327315
if (npoints > 1) {
328-
n = _twin_edge_build(path->points + p, npoints, edges + nedges, sdx,
316+
int n =
317+
_twin_edge_build(path->points + p, npoints, edges + nedges, sdx,
329318
sdy, twin_int_to_sfixed(pixmap->clip.top));
330319
p = sublen;
331320
nedges += n;

src/timeout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ void _twin_run_timeout(void)
3434
{
3535
twin_time_t now = twin_now();
3636
twin_timeout_t *timeout;
37-
twin_timeout_t *first;
3837
twin_time_t delay;
3938

40-
first = (twin_timeout_t *) _twin_queue_set_order(&head);
39+
twin_timeout_t *first = (twin_timeout_t *) _twin_queue_set_order(&head);
4140
for (timeout = first; timeout && twin_time_compare(now, >=, timeout->time);
4241
timeout = (twin_timeout_t *) timeout->queue.order) {
4342
delay = (*timeout->proc)(now, timeout->closure);

0 commit comments

Comments
 (0)