# HG changeset patch # User Matti Hamalainen # Date 1525980602 -10800 # Node ID 0046b4e1b35f11e862fdfc046c3c1027bfe0e1a9 # Parent d14d1101616f5363887e2d317da20a9cdf0fc1eb Various fixes in bmp encoding. diff -r d14d1101616f -r 0046b4e1b35f tools/lib64gfx.c --- a/tools/lib64gfx.c Thu May 10 21:57:20 2018 +0300 +++ b/tools/lib64gfx.c Thu May 10 22:30:02 2018 +0300 @@ -1350,7 +1350,7 @@ { int res = DMERR_OK; - if (buf == NULL || img == NULL || fmt == NULL) + if (img == NULL || fmt == NULL) return DMERR_NULLPTR; // Allocate the output buffer @@ -1361,6 +1361,7 @@ fmt->size); goto err; } + buf->len = fmt->size; // Perform encoding for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) @@ -1725,15 +1726,18 @@ goto err; // Add the loading address - if ((res = dmGrowBufGrow(buf, 2)) != DMERR_OK) + if (!dmGrowBufGrow(buf, 2)) + { + res = DMERR_MALLOC; goto err; + } memmove(buf->data + 2, buf->data, buf->len); buf->data[0] = DM_GET_ADDR_LO(fmt->addr); buf->data[1] = DM_GET_ADDR_HI(fmt->addr); - buf->len += 2; + return DMERR_OK; err: dmGrowBufFree(buf);