Mercurial > hg > dmlib
changeset 2449:ff639208aae6
Reorder few NULL checks to be earlier.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 15 Apr 2020 13:30:16 +0300 |
parents | cd5805f392a9 |
children | dc92cf744ad9 |
files | tools/gfxconv.c |
diffstat | 1 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/gfxconv.c Wed Apr 15 13:29:50 2020 +0300 +++ b/tools/gfxconv.c Wed Apr 15 13:30:16 2020 +0300 @@ -1071,6 +1071,13 @@ int n, index, xc, yc, ncolors, res = DMERR_OK; DMImage *dst; + if (mapping == NULL || mapped == NULL || used == NULL) + { + res = dmError(DMERR_MALLOC, + "Could not allocate memory for reused palette.\n"); + goto error; + } + if ((res = dmPaletteAlloc(&tmpPal, src->pal->ncolors, -1)) != DMERR_OK) { dmErrorMsg("Could not allocate memory for remap palette.\n"); @@ -1084,25 +1091,18 @@ goto error; } - - if (mapping == NULL || mapped == NULL || used == NULL) - { - res = dmError(DMERR_MALLOC, - "Could not allocate memory for reused palette.\n"); - goto error; - } - dmMsg(1, "Remapping %d output image colors of %d colors.\n", optNRemapTable, src->pal->ncolors); + + // Find used colors + dmMsg(2, "Scanning image for used colors...\n"); for (index = 0; index < src->pal->ncolors; index++) { mapping[index] = -1; mapped[index] = used[index] = FALSE; } - // Find used colors - dmMsg(2, "Scanning image for used colors...\n"); for (ncolors = yc = 0; yc < src->height; yc++) { const Uint8 *dp = src->data + src->pitch * yc;