aboutsummaryrefslogtreecommitdiff
path: root/src/zopfli/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zopfli/cache.c')
-rw-r--r--src/zopfli/cache.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/zopfli/cache.c b/src/zopfli/cache.c
index 88a49ac..6b9444f 100644
--- a/src/zopfli/cache.c
+++ b/src/zopfli/cache.c
@@ -31,6 +31,12 @@ void ZopfliInitCache(size_t blocksize, ZopfliLongestMatchCache* lmc) {
lmc->dist = (unsigned short*)malloc(sizeof(unsigned short) * blocksize);
/* Rather large amount of memory. */
lmc->sublen = (unsigned char*)malloc(ZOPFLI_CACHE_LENGTH * 3 * blocksize);
+ if(lmc->sublen == NULL) {
+ fprintf(stderr,
+ "Error: Out of memory. Tried allocating %lu bytes of memory.\n",
+ (unsigned long)ZOPFLI_CACHE_LENGTH * 3 * blocksize);
+ exit (EXIT_FAILURE);
+ }
/* length > 0 and dist 0 is invalid combination, which indicates on purpose
that this cache value is not filled in yet. */