static SquashStatus squash_lzg_decompress_buffer (SquashCodec* codec, size_t* decompressed_size, uint8_t decompressed[HEDLEY_ARRAY_PARAM(*decompressed_size)], size_t compressed_size, const uint8_t compressed[HEDLEY_ARRAY_PARAM(compressed_size)], SquashOptions* options) { lzg_uint32_t res; #if UINT32_MAX < SIZE_MAX if (HEDLEY_UNLIKELY(UINT32_MAX < compressed_size) || HEDLEY_UNLIKELY(UINT32_MAX < *decompressed_size)) return squash_error (SQUASH_RANGE); #endif if (LZG_DecodedSize ((const unsigned char*) compressed, (lzg_uint32_t) compressed_size) > *decompressed_size) return squash_error (SQUASH_BUFFER_FULL); res = LZG_Decode ((const unsigned char*) compressed, (lzg_uint32_t) compressed_size, (unsigned char*) decompressed, (lzg_uint32_t) *decompressed_size); if (HEDLEY_UNLIKELY(res == 0)) { return squash_error (SQUASH_FAILED); } else { #if SIZE_MAX < UINT32_MAX if (HEDLEY_UNLIKELY(SIZE_MAX < res)) return squash_error (SQUASH_RANGE); #endif *decompressed_size = (size_t) res; return SQUASH_OK; } }
uint32_t flash_part(struct ota * ota, uint32_t to, uint32_t size, uint32_t index, uint32_t type) { const uint8_t *r_offset; uint8_t *w_offset; uint32_t w_size; uint32_t r_size; uint32_t success; r_offset = ota->payload + ota->header.binaries[index].offset; w_offset = (uint8_t *) (to * PAGE_SIZE); r_size = ota->header.binaries[index].length; w_size = size * PAGE_SIZE; if (w_size < r_size) return OTA_PART_TOO_SMALL_ERROR; if (ota->header.binaries[index].type != type) return OTA_BINARY_TYPE_ERROR; ota_erase_partition(to, size); success = LZG_Decode(r_offset, r_size, w_offset, w_size); if (success) return OTA_SUCCESS; return OTA_LZG_ERROR; }
int64_t lzbench_lzg_decompress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t, size_t, char*) { return LZG_Decode((const unsigned char*)inbuf, insize, (unsigned char*)outbuf, outsize); }