Skip to content

Commit

Permalink
Merge pull request #201 from mickeprag/micke/font_uncompressor_in_heap
Browse files Browse the repository at this point in the history
Place tinfl_decompressor in heap. Thanks @mickeprag
  • Loading branch information
martinberlin committed Aug 29, 2022
2 parents 3e2c515 + 5953219 commit 5249bed
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/epd_driver/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ static utf_t *utf[] = {
&(utf_t){0},
};

/**
* static decompressor object for compressed fonts.
*/
static tinfl_decompressor decomp;

static inline int min(int x, int y) { return x < y ? x : y; }
static inline int max(int x, int y) { return x > y ? x : y; }

Expand Down Expand Up @@ -94,13 +89,20 @@ const EpdGlyph* epd_get_glyph(const EpdFont *font, uint32_t code_point) {
}

static int uncompress(uint8_t *dest, uint32_t uncompressed_size, const uint8_t *source, uint32_t source_size) {
tinfl_decompressor *decomp;
if (uncompressed_size == 0 || dest == NULL || source_size == 0 || source == NULL) {
return -1;
}
tinfl_init(&decomp);
decomp = malloc(sizeof(tinfl_decompressor));
if (!decomp) {
// Out of memory
return -1;
}
tinfl_init(decomp);

// we know everything will fit into the buffer.
tinfl_status decomp_status = tinfl_decompress(&decomp, source, &source_size, dest, dest, &uncompressed_size, TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
tinfl_status decomp_status = tinfl_decompress(decomp, source, &source_size, dest, dest, &uncompressed_size, TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
free(decomp);
if (decomp_status != TINFL_STATUS_DONE) {
return decomp_status;
}
Expand Down

0 comments on commit 5249bed

Please sign in to comment.