# HG changeset patch # User Matti Hamalainen # Date 1586946616 -10800 # Node ID ff639208aae676c99edfb06008c0ded5dd1285c0 # Parent cd5805f392a9ec0eaeac97c281ddf883a260bcb7 Reorder few NULL checks to be earlier. diff -r cd5805f392a9 -r ff639208aae6 tools/gfxconv.c --- 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;