diff options
author | Kim Woelders <kim@woelders.dk> | 2018-07-21 13:21:32 +0200 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2018-07-21 15:26:34 +0200 |
commit | 5051ef9249a9d9a3ab62dcb5e9464091eb8a3120 (patch) | |
tree | 5aa32606a025ffbb4d31944911dce510fa23e60c | |
parent | 6ea4cf7e66685d399e60ca9f14236827b1fa4374 (diff) | |
download | imlib2-5051ef9249a9d9a3ab62dcb5e9464091eb8a3120.tar.gz |
XPM loader: More simplifications
In particular, remove redundant and bogus loop conditions.
-rw-r--r-- | src/modules/loaders/loader_xpm.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/modules/loaders/loader_xpm.c b/src/modules/loaders/loader_xpm.c index c316a04..44b2bce 100644 --- a/src/modules/loaders/loader_xpm.c +++ b/src/modules/loaders/loader_xpm.c @@ -98,7 +98,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, char immediate_load) { int rc; - DATA32 *ptr, *end; + DATA32 *ptr; FILE *f; int pc, c, i, j, k, w, h, ncolors, cpp; int comment, transp, quote, context, len, done, backslash; @@ -140,7 +140,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, ncolors = 0; cpp = 0; ptr = NULL; - end = NULL; c = ' '; comment = 0; quote = 0; @@ -150,6 +149,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, line = malloc(lsz); if (!line) goto quit; + len = 0; backslash = 0; memset(lookup, 0, sizeof(lookup)); @@ -174,11 +174,11 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, if ((!quote) && (c == '"')) { quote = 1; - i = 0; + len = 0; } else if ((quote) && (c == '"')) { - line[i] = 0; + line[len] = 0; quote = 0; if (context == 0) { @@ -220,7 +220,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, goto quit; ptr = im->data; pixels = w * h; - end = ptr + (pixels); } else { @@ -244,7 +243,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, tok[0] = 0; col[0] = 0; s[0] = 0; - len = strlen(line); if (len < cpp) goto quit; strncpy(cmap[j].str, line, cpp); @@ -335,8 +333,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, if (cpp == 1) { #define CM1(c0) (&cmap[lookup[c0 - ' '][0]]) - for (i = 0; - ((i < 65536) && (ptr < end) && (line[i])); i++) + for (i = 0; count < pixels && i < len; i++) { *ptr++ = CM1(line[i])->pixel; count++; @@ -345,9 +342,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, else if (cpp == 2) { #define CM2(c0, c1) (&cmap[lookup[c0 - ' '][c1 - ' ']]) - for (i = 0; - ((i < 65536) && (ptr < end) - && (line[i]) && (line[i + 1])); i += 2) + for (i = 0; count < pixels && i < len - 1; i += 2) { *ptr++ = CM2(line[i], line[i + 1])->pixel; count++; @@ -356,15 +351,12 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, else { #define CMn(_j) (&cmap[_j]) - for (i = 0; - ((i < 65536) && (ptr < end) && (line[i])); i++) + for (i = 0; count < pixels && i < len - (cpp - 1); + i += cpp) { - for (j = 0; ((j < cpp) && (line[i])); j++, i++) - { - col[j] = line[i]; - } + for (j = 0; j < cpp; j++) + col[j] = line[i + j]; col[j] = 0; - i--; for (j = 0; j < ncolors; j++) { if (!strcmp(col, cmap[j].str)) @@ -402,7 +394,7 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, { if (++backslash < 2) { - line[i++] = c; + line[len++] = c; } else { @@ -412,11 +404,11 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity, else { backslash = 0; - line[i++] = c; + line[len++] = c; } } - if (i >= lsz) + if (len >= lsz) { char *nline; |