summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-04-11 20:12:13 +0200
committerKim Woelders <kim@woelders.dk>2021-04-16 17:15:06 +0200
commite82a5997ecf595ceb1ede964337733beb47cb94c (patch)
tree8e322c603bcc81d5f9c43165e89d789e7d1e099a
parent6f4dc94cc45c937c902a4cf3619febdb8bac16cd (diff)
Fix clang-analyzer warnings - lib (mostly trivial)
-rw-r--r--src/lib/api.c1
-rw-r--r--src/lib/blend.c4
-rw-r--r--src/lib/file.c3
-rw-r--r--src/lib/font_draw.c1
-rw-r--r--src/lib/font_main.c14
-rw-r--r--src/lib/grad.c26
-rw-r--r--src/lib/rgbadraw.c86
-rw-r--r--src/lib/rotate.c2
-rw-r--r--src/lib/scale.c10
-rw-r--r--src/lib/script.c17
10 files changed, 89 insertions, 75 deletions
diff --git a/src/lib/api.c b/src/lib/api.c
index 40e1658..3f65bba 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -3673,6 +3673,7 @@ imlib_text_get_location_at_index(const char *text, int index,
3673 3673
3674 __imlib_font_query_char_coords(fn, text, index, &cx, &cy, &cw, &ch); 3674 __imlib_font_query_char_coords(fn, text, index, &cx, &cy, &cw, &ch);
3675 3675
3676 w = h = 0;
3676 imlib_get_text_size(text, &w, &h); 3677 imlib_get_text_size(text, &w, &h);
3677 3678
3678 switch (ctx->direction) 3679 switch (ctx->direction)
diff --git a/src/lib/blend.c b/src/lib/blend.c
index 7566de2..76b6d04 100644
--- a/src/lib/blend.c
+++ b/src/lib/blend.c
@@ -1894,10 +1894,6 @@ __imlib_BlendImageToImage(ImlibImage * im_src, ImlibImage * im_dst,
1894 if ((dw < 1) || (dh < 1)) 1894 if ((dw < 1) || (dh < 1))
1895 return; 1895 return;
1896 } 1896 }
1897 if (psx != dx)
1898 sx += ((dx - psx) * ssw) / abs(ddw);
1899 if (psy != dy)
1900 sy += ((dy - psy) * ssh) / abs(ddh);
1901 if (psw != dw) 1897 if (psw != dw)
1902 sw = (sw * dw) / psw; 1898 sw = (sw * dw) / psw;
1903 if (psh != dh) 1899 if (psh != dh)
diff --git a/src/lib/file.c b/src/lib/file.c
index 7dcd219..4f7c43a 100644
--- a/src/lib/file.c
+++ b/src/lib/file.c
@@ -210,7 +210,8 @@ __imlib_FileDir(const char *dir, int *num)
210 return NULL; 210 return NULL;
211 } 211 }
212 /* count # of entries in dir (worst case) */ 212 /* count # of entries in dir (worst case) */
213 for (dirlen = 0; (dp = readdir(dirp)); dirlen++); 213 for (dirlen = 0; readdir(dirp) != NULL; dirlen++)
214 ;
214 if (!dirlen) 215 if (!dirlen)
215 { 216 {
216 closedir(dirp); 217 closedir(dirp);
diff --git a/src/lib/font_draw.c b/src/lib/font_draw.c
index ea49e14..9756f9c 100644
--- a/src/lib/font_draw.c
+++ b/src/lib/font_draw.c
@@ -97,6 +97,7 @@ __imlib_render_str(ImlibImage * im, ImlibFont * fn, int drx, int dry,
97 97
98 ascent = __imlib_font_max_ascent_get(fn); 98 ascent = __imlib_font_max_ascent_get(fn);
99 99
100 nx = ny = 0;
100 __imlib_font_draw(im2, pixel, fn, 0, ascent, text, &nx, &ny, 0, 0, w, h); 101 __imlib_font_draw(im2, pixel, fn, 0, ascent, text, &nx, &ny, 0, 0, w, h);
101 102
102 /* OK, now we have small ImlibImage with text rendered, 103 /* OK, now we have small ImlibImage with text rendered,
diff --git a/src/lib/font_main.c b/src/lib/font_main.c
index ad47167..e3b6eb5 100644
--- a/src/lib/font_main.c
+++ b/src/lib/font_main.c
@@ -360,18 +360,16 @@ __imlib_hash_free(Imlib_Hash * hash)
360 360
361 if (!hash) 361 if (!hash)
362 return; 362 return;
363
363 size = __imlib_hash_size(hash); 364 size = __imlib_hash_size(hash);
364 for (i = 0; i < size; i++) 365 for (i = 0; i < size; i++)
365 { 366 {
366 while (hash->buckets[i]) 367 Imlib_Hash_El *el, *el_next;
367 {
368 Imlib_Hash_El *el;
369 368
370 el = (Imlib_Hash_El *) hash->buckets[i]; 369 for (el = (Imlib_Hash_El *) hash->buckets[i]; el; el = el_next)
371 if (el->key) 370 {
372 free(el->key); 371 el_next = (Imlib_Hash_El *) el->_list_data.next;
373 hash->buckets[i] = 372 free(el->key);
374 __imlib_object_list_remove(hash->buckets[i], el);
375 free(el); 373 free(el);
376 } 374 }
377 } 375 }
diff --git a/src/lib/grad.c b/src/lib/grad.c
index 5686a9e..b3df3a3 100644
--- a/src/lib/grad.c
+++ b/src/lib/grad.c
@@ -94,7 +94,7 @@ __imlib_MapRange(ImlibRange * rg, int len)
94 for (p = rg->color; p; p = p->next) 94 for (p = rg->color; p; p = p->next)
95 ll += p->distance; 95 ll += p->distance;
96 map = malloc(len * sizeof(DATA32)); 96 map = malloc(len * sizeof(DATA32));
97 pmap = malloc(ll * sizeof(DATA32)); 97 pmap = calloc(ll, sizeof(DATA32));
98 i = 0; 98 i = 0;
99 for (p = rg->color; p; p = p->next) 99 for (p = rg->color; p; p = p->next)
100 { 100 {
@@ -166,7 +166,7 @@ __imlib_MapHsvaRange(ImlibRange * rg, int len)
166 for (p = rg->color; p; p = p->next) 166 for (p = rg->color; p; p = p->next)
167 ll += p->distance; 167 ll += p->distance;
168 map = malloc(len * sizeof(DATA32)); 168 map = malloc(len * sizeof(DATA32));
169 pmap = malloc(ll * sizeof(DATA32)); 169 pmap = calloc(ll, sizeof(DATA32));
170 i = 0; 170 i = 0;
171 for (p = rg->color; p; p = p->next) 171 for (p = rg->color; p; p = p->next)
172 { 172 {
@@ -286,15 +286,23 @@ __imlib_DrawGradient(ImlibImage * im, int x, int y, int w, int h,
286 yoff += (y - py); 286 yoff += (y - py);
287 } 287 }
288 288
289 vlut = NULL;
290 map = NULL;
291
289 hlut = malloc(sizeof(int) * ww); 292 hlut = malloc(sizeof(int) * ww);
293 if (!hlut)
294 goto quit;
290 vlut = malloc(sizeof(int) * hh); 295 vlut = malloc(sizeof(int) * hh);
296 if (!vlut)
297 goto quit;
298
291 if (ww > hh) 299 if (ww > hh)
292 len = ww * 16; 300 len = ww * 16;
293 else 301 else
294 len = hh * 16; 302 len = hh * 16;
295 map = __imlib_MapRange(rg, len); 303 map = __imlib_MapRange(rg, len);
296 if (!map) 304 if (!map)
297 return; 305 goto quit;
298 306
299 xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360)); 307 xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360));
300 yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360)); 308 yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360));
@@ -423,6 +431,7 @@ __imlib_DrawGradient(ImlibImage * im, int x, int y, int w, int h,
423 break; 431 break;
424 } 432 }
425 433
434 quit:
426 free(vlut); 435 free(vlut);
427 free(hlut); 436 free(hlut);
428 free(map); 437 free(map);
@@ -479,15 +488,23 @@ __imlib_DrawHsvaGradient(ImlibImage * im, int x, int y, int w, int h,
479 yoff += (y - py); 488 yoff += (y - py);
480 } 489 }
481 490
491 vlut = NULL;
492 map = NULL;
493
482 hlut = malloc(sizeof(int) * ww); 494 hlut = malloc(sizeof(int) * ww);
495 if (!hlut)
496 goto quit;
483 vlut = malloc(sizeof(int) * hh); 497 vlut = malloc(sizeof(int) * hh);
498 if (!vlut)
499 goto quit;
500
484 if (ww > hh) 501 if (ww > hh)
485 len = ww * 16; 502 len = ww * 16;
486 else 503 else
487 len = hh * 16; 504 len = hh * 16;
488 map = __imlib_MapHsvaRange(rg, len); 505 map = __imlib_MapHsvaRange(rg, len);
489 if (!map) 506 if (!map)
490 return; 507 goto quit;
491 508
492 xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360)); 509 xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360));
493 yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360)); 510 yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360));
@@ -616,6 +633,7 @@ __imlib_DrawHsvaGradient(ImlibImage * im, int x, int y, int w, int h,
616 break; 633 break;
617 } 634 }
618 635
636 quit:
619 free(vlut); 637 free(vlut);
620 free(hlut); 638 free(hlut);
621 free(map); 639 free(map);
diff --git a/src/lib/rgbadraw.c b/src/lib/rgbadraw.c
index 7a4e932..670ebcd 100644
--- a/src/lib/rgbadraw.c
+++ b/src/lib/rgbadraw.c
@@ -94,7 +94,6 @@ __imlib_FlipImageDiagonal(ImlibImage * im, int direction)
94 int x, y, w, hw, tmp; 94 int x, y, w, hw, tmp;
95 95
96 data = malloc(im->w * im->h * sizeof(DATA32)); 96 data = malloc(im->w * im->h * sizeof(DATA32));
97 from = im->data;
98 w = im->h; 97 w = im->h;
99 im->h = im->w; 98 im->h = im->w;
100 im->w = w; 99 im->w = w;
@@ -143,6 +142,7 @@ __imlib_FlipImageDiagonal(ImlibImage * im, int direction)
143 hw = hw - 1; 142 hw = hw - 1;
144 break; 143 break;
145 } 144 }
145
146 from = im->data; 146 from = im->data;
147 for (x = im->w; --x >= 0;) 147 for (x = im->w; --x >= 0;)
148 { 148 {
@@ -253,53 +253,55 @@ __imlib_SharpenImage(ImlibImage * im, int rad)
253 DATA32 *data, *p1, *p2; 253 DATA32 *data, *p1, *p2;
254 int a, r, g, b, x, y; 254 int a, r, g, b, x, y;
255 255
256 data = malloc(im->w * im->h * sizeof(DATA32));
257 if (rad == 0) 256 if (rad == 0)
258 return; 257 return;
259 else 258
259 data = malloc(im->w * im->h * sizeof(DATA32));
260 if (!data)
261 return;
262
263 for (y = 1; y < (im->h - 1); y++)
260 { 264 {
261 for (y = 1; y < (im->h - 1); y++) 265 p1 = im->data + 1 + (y * im->w);
266 p2 = data + 1 + (y * im->w);
267 for (x = 1; x < (im->w - 1); x++)
262 { 268 {
263 p1 = im->data + 1 + (y * im->w); 269 b = (int)((p1[0]) & 0xff) * 5;
264 p2 = data + 1 + (y * im->w); 270 g = (int)((p1[0] >> 8) & 0xff) * 5;
265 for (x = 1; x < (im->w - 1); x++) 271 r = (int)((p1[0] >> 16) & 0xff) * 5;
266 { 272 a = (int)((p1[0] >> 24) & 0xff) * 5;
267 b = (int)((p1[0]) & 0xff) * 5; 273 b -= (int)((p1[-1]) & 0xff);
268 g = (int)((p1[0] >> 8) & 0xff) * 5; 274 g -= (int)((p1[-1] >> 8) & 0xff);
269 r = (int)((p1[0] >> 16) & 0xff) * 5; 275 r -= (int)((p1[-1] >> 16) & 0xff);
270 a = (int)((p1[0] >> 24) & 0xff) * 5; 276 a -= (int)((p1[-1] >> 24) & 0xff);
271 b -= (int)((p1[-1]) & 0xff); 277 b -= (int)((p1[1]) & 0xff);
272 g -= (int)((p1[-1] >> 8) & 0xff); 278 g -= (int)((p1[1] >> 8) & 0xff);
273 r -= (int)((p1[-1] >> 16) & 0xff); 279 r -= (int)((p1[1] >> 16) & 0xff);
274 a -= (int)((p1[-1] >> 24) & 0xff); 280 a -= (int)((p1[1] >> 24) & 0xff);
275 b -= (int)((p1[1]) & 0xff); 281 b -= (int)((p1[-im->w]) & 0xff);
276 g -= (int)((p1[1] >> 8) & 0xff); 282 g -= (int)((p1[-im->w] >> 8) & 0xff);
277 r -= (int)((p1[1] >> 16) & 0xff); 283 r -= (int)((p1[-im->w] >> 16) & 0xff);
278 a -= (int)((p1[1] >> 24) & 0xff); 284 a -= (int)((p1[-im->w] >> 24) & 0xff);
279 b -= (int)((p1[-im->w]) & 0xff); 285 b -= (int)((p1[im->w]) & 0xff);
280 g -= (int)((p1[-im->w] >> 8) & 0xff); 286 g -= (int)((p1[im->w] >> 8) & 0xff);
281 r -= (int)((p1[-im->w] >> 16) & 0xff); 287 r -= (int)((p1[im->w] >> 16) & 0xff);
282 a -= (int)((p1[-im->w] >> 24) & 0xff); 288 a -= (int)((p1[im->w] >> 24) & 0xff);
283 b -= (int)((p1[im->w]) & 0xff); 289
284 g -= (int)((p1[im->w] >> 8) & 0xff); 290 a = (a & ((~a) >> 16));
285 r -= (int)((p1[im->w] >> 16) & 0xff); 291 a = ((a | ((a & 256) - ((a & 256) >> 8))));
286 a -= (int)((p1[im->w] >> 24) & 0xff); 292 r = (r & ((~r) >> 16));
287 293 r = ((r | ((r & 256) - ((r & 256) >> 8))));
288 a = (a & ((~a) >> 16)); 294 g = (g & ((~g) >> 16));
289 a = ((a | ((a & 256) - ((a & 256) >> 8)))); 295 g = ((g | ((g & 256) - ((g & 256) >> 8))));
290 r = (r & ((~r) >> 16)); 296 b = (b & ((~b) >> 16));
291 r = ((r | ((r & 256) - ((r & 256) >> 8)))); 297 b = ((b | ((b & 256) - ((b & 256) >> 8))));
292 g = (g & ((~g) >> 16)); 298
293 g = ((g | ((g & 256) - ((g & 256) >> 8)))); 299 *p2 = PIXEL_ARGB(a, r, g, b);
294 b = (b & ((~b) >> 16)); 300 p2++;
295 b = ((b | ((b & 256) - ((b & 256) >> 8)))); 301 p1++;
296
297 *p2 = PIXEL_ARGB(a, r, g, b);
298 p2++;
299 p1++;
300 }
301 } 302 }
302 } 303 }
304
303 __imlib_ReplaceData(im, data); 305 __imlib_ReplaceData(im, data);
304} 306}
305 307
diff --git a/src/lib/rotate.c b/src/lib/rotate.c
index 65ea28b..4b9b7b9 100644
--- a/src/lib/rotate.c
+++ b/src/lib/rotate.c
@@ -45,7 +45,7 @@
45/*\ One colour, alpha between one value and three zeroes \*/ 45/*\ One colour, alpha between one value and three zeroes \*/
46#define INTERP_A000(dest, v, f1, f2) do { \ 46#define INTERP_A000(dest, v, f1, f2) do { \
47 *(dest) = *(v); \ 47 *(dest) = *(v); \
48 A_VAL(dest) = (A_VAL(dest) * \ 48 A_VAL(dest) = (A_VAL(v) * \
49 ((f1) & _ROTATE_PREC_BITS) * ((f2) & _ROTATE_PREC_BITS)) >> (2 * _ROTATE_PREC); \ 49 ((f1) & _ROTATE_PREC_BITS) * ((f2) & _ROTATE_PREC_BITS)) >> (2 * _ROTATE_PREC); \
50 } while (0) 50 } while (0)
51 51
diff --git a/src/lib/scale.c b/src/lib/scale.c
index 9c63ffc..a94f13c 100644
--- a/src/lib/scale.c
+++ b/src/lib/scale.c
@@ -54,7 +54,7 @@ __imlib_CalcYPoints(DATA32 * src, int sw, int sh, int dh, int b1, int b2)
54 if (dh > (b1 + b2)) 54 if (dh > (b1 + b2))
55 { 55 {
56 val = (b1 << 16); 56 val = (b1 << 16);
57 inc = ((sh - b1 - b2) << 16) / (dh - b1 - b2); 57 inc = ((sh - b1 - b2) << 16) / (dh - (b1 + b2));
58 for (i = 0; i < (dh - b1 - b2); i++) 58 for (i = 0; i < (dh - b1 - b2); i++)
59 { 59 {
60 p[j++] = src + ((val >> 16) * sw); 60 p[j++] = src + ((val >> 16) * sw);
@@ -112,7 +112,7 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2)
112 if (dw > (b1 + b2)) 112 if (dw > (b1 + b2))
113 { 113 {
114 val = (b1 << 16); 114 val = (b1 << 16);
115 inc = ((sw - b1 - b2) << 16) / (dw - b1 - b2); 115 inc = ((sw - b1 - b2) << 16) / (dw - (b1 + b2));
116 for (i = 0; i < (dw - b1 - b2); i++) 116 for (i = 0; i < (dw - b1 - b2); i++)
117 { 117 {
118 p[j++] = (val >> 16); 118 p[j++] = (val >> 16);
@@ -193,8 +193,8 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
193 { 193 {
194 int ss, dd, ap, Cp; 194 int ss, dd, ap, Cp;
195 195
196 ss = s - b1 - b2; 196 ss = s - (b1 + b2);
197 dd = d - b1 - b2; 197 dd = d - (b1 + b2);
198 val = 0; 198 val = 0;
199 inc = (ss << 16) / dd; 199 inc = (ss << 16) / dd;
200 Cp = ((dd << 14) / ss) + 1; 200 Cp = ((dd << 14) / ss) + 1;
@@ -868,7 +868,6 @@ __imlib_ScaleAARGBA(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy,
868 if (j > 0) 868 if (j > 0)
869 { 869 {
870 pix = sptr; 870 pix = sptr;
871 sptr += sow;
872 rx = (R_VAL(pix) * xap) >> 9; 871 rx = (R_VAL(pix) * xap) >> 9;
873 gx = (G_VAL(pix) * xap) >> 9; 872 gx = (G_VAL(pix) * xap) >> 9;
874 bx = (B_VAL(pix) * xap) >> 9; 873 bx = (B_VAL(pix) * xap) >> 9;
@@ -1454,7 +1453,6 @@ __imlib_ScaleAARGB(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy,
1454 if (j > 0) 1453 if (j > 0)
1455 { 1454 {
1456 pix = sptr; 1455 pix = sptr;
1457 sptr += sow;
1458 rx = (R_VAL(pix) * xap) >> 9; 1456 rx = (R_VAL(pix) * xap) >> 9;
1459 gx = (G_VAL(pix) * xap) >> 9; 1457 gx = (G_VAL(pix) * xap) >> 9;
1460 bx = (B_VAL(pix) * xap) >> 9; 1458 bx = (B_VAL(pix) * xap) >> 9;
diff --git a/src/lib/script.c b/src/lib/script.c
index be34944..9072ff4 100644
--- a/src/lib/script.c
+++ b/src/lib/script.c
@@ -59,15 +59,15 @@ static char *
59__imlib_copystr(const char *str, int start, int end) 59__imlib_copystr(const char *str, int start, int end)
60{ 60{
61 int i = 0; 61 int i = 0;
62 char *rstr = calloc(1024, sizeof(char)); 62 char *rstr;
63 63
64 if (start <= end && end < (int)strlen(str)) 64 if (start > end || end >= (int)strlen(str))
65 { 65 return NULL;
66 for (i = start; i <= end; i++) 66
67 rstr[i - start] = str[i]; 67 rstr = calloc(1024, sizeof(char));
68 return rstr; 68 for (i = start; i <= end; i++)
69 } 69 rstr[i - start] = str[i];
70 return NULL; 70 return rstr;
71} 71}
72 72
73static void 73static void
@@ -267,7 +267,6 @@ __imlib_script_parse(ImlibImage * im, const char *script, va_list param_list)
267 } 267 }
268 268
269 start = 0; 269 start = 0;
270 i = 0;
271 script_len = strlen(scriptbuf); 270 script_len = strlen(scriptbuf);
272 for (i = 0; i < script_len; i++) 271 for (i = 0; i < script_len; i++)
273 { 272 {