summaryrefslogtreecommitdiffstats
path: root/lz4.c
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-04-13 09:31:22 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-04-13 09:31:22 (GMT)
commitcbfd031d301222123d185320a55a923f9363f781 (patch)
tree4d1b6bee26974c0bb98ec3c2989e8e1d81da3046 /lz4.c
parent647baabcef0effcfcb3cc0dadb2970db681c9d52 (diff)
downloadlz4-cbfd031d301222123d185320a55a923f9363f781.zip
lz4-cbfd031d301222123d185320a55a923f9363f781.tar.gz
lz4-cbfd031d301222123d185320a55a923f9363f781.tar.bz2
Added : LZ4 Streaming Format specification (v1.3)
Added : LZ4c command-line utility, supporting the new streaming format Added : xxhash library Removed : lz4demo is now replaced by lz4.c Removed : a few level 4 warnings (issue 64) Updated : makefiles git-svn-id: https://lz4.googlecode.com/svn/trunk@92 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
Diffstat (limited to 'lz4.c')
-rw-r--r--lz4.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/lz4.c b/lz4.c
index f15dcfc..2660f5d 100644
--- a/lz4.c
+++ b/lz4.c
@@ -1,6 +1,6 @@
/*
LZ4 - Fast LZ compression algorithm
- Copyright (C) 2011-2012, Yann Collet.
+ Copyright (C) 2011-2013, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
@@ -110,6 +110,7 @@
# pragma intrinsic(_BitScanForward) // For Visual 2005
# pragma intrinsic(_BitScanReverse) // For Visual 2005
# endif
+# pragma warning(disable : 4127) // disable: C4127: conditional expression is constant
#endif
#ifdef _MSC_VER
@@ -141,17 +142,17 @@
//**************************************
#if defined(_MSC_VER) // Visual Studio does not support 'stdint' natively
# define BYTE unsigned __int8
-# define U16 unsigned __int16
-# define U32 unsigned __int32
-# define S32 __int32
-# define U64 unsigned __int64
+# define U16 unsigned __int16
+# define U32 unsigned __int32
+# define S32 __int32
+# define U64 unsigned __int64
#else
# include <stdint.h>
# define BYTE uint8_t
-# define U16 uint16_t
-# define U32 uint32_t
-# define S32 int32_t
-# define U64 uint64_t
+# define U16 uint16_t
+# define U32 uint32_t
+# define S32 int32_t
+# define U64 uint64_t
#endif
#ifndef LZ4_FORCE_UNALIGNED_ACCESS
@@ -378,7 +379,7 @@ static inline int LZ4_compressCtx(void** ctx,
// First Byte
- HashTable[LZ4_HASH_VALUE(ip)] = ip - base;
+ HashTable[LZ4_HASH_VALUE(ip)] = (HTYPE)(ip - base);
ip++; forwardH = LZ4_HASH_VALUE(ip);
// Main Loop
@@ -400,7 +401,7 @@ static inline int LZ4_compressCtx(void** ctx,
forwardH = LZ4_HASH_VALUE(forwardIp);
ref = base + HashTable[h];
- HashTable[h] = ip - base;
+ HashTable[h] = (HTYPE)(ip - base);
} while ((ref < ip - MAX_DISTANCE) || (A32(ref) != A32(ip)));
@@ -427,7 +428,7 @@ static inline int LZ4_compressCtx(void** ctx,
else
*op++ = (BYTE)len;
}
- else *token = (length<<ML_BITS);
+ else *token = (BYTE)(length<<ML_BITS);
#else
if (length>=(int)RUN_MASK)
{
@@ -473,17 +474,17 @@ _endCount:
if (length > 254) { length-=255; *op++ = 255; }
*op++ = (BYTE)length;
}
- else *token += length;
+ else *token += (BYTE)length;
// Test end of chunk
if (ip > mflimit) { anchor = ip; break; }
// Fill table
- HashTable[LZ4_HASH_VALUE(ip-2)] = ip - 2 - base;
+ HashTable[LZ4_HASH_VALUE(ip-2)] = (HTYPE)(ip - 2 - base);
// Test next position
ref = base + HashTable[LZ4_HASH_VALUE(ip)];
- HashTable[LZ4_HASH_VALUE(ip)] = ip - base;
+ HashTable[LZ4_HASH_VALUE(ip)] = (HTYPE)(ip - base);
if ((ref > ip - (MAX_DISTANCE + 1)) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
// Prepare next loop
@@ -497,7 +498,7 @@ _last_literals:
int lastRun = (int)(iend - anchor);
if (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) return 0;
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
- else *op++ = (lastRun<<ML_BITS);
+ else *op++ = (BYTE)(lastRun<<ML_BITS);
memcpy(op, anchor, iend - anchor);
op += iend-anchor;
}
@@ -606,7 +607,7 @@ static inline int LZ4_compress64kCtx(void** ctx,
else
*op++ = (BYTE)len;
}
- else *token = (length<<ML_BITS);
+ else *token = (BYTE)(length<<ML_BITS);
#else
if (length>=(int)RUN_MASK) { *token=(RUN_MASK<<ML_BITS); len = length-RUN_MASK; for(; len > 254 ; len-=255) *op++ = 255; *op++ = (BYTE)len; }
else *token = (length<<ML_BITS);
@@ -638,7 +639,7 @@ _endCount:
len = (int)(ip - anchor);
if unlikely(op + (1 + LASTLITERALS) + (len>>8) > oend) return 0; // Check output limit
if (len>=(int)ML_MASK) { *token+=ML_MASK; len-=ML_MASK; for(; len > 509 ; len-=510) { *op++ = 255; *op++ = 255; } if (len > 254) { len-=255; *op++ = 255; } *op++ = (BYTE)len; }
- else *token += len;
+ else *token += (BYTE)len;
// Test end of chunk
if (ip > mflimit) { anchor = ip; break; }
@@ -662,7 +663,7 @@ _last_literals:
int lastRun = (int)(iend - anchor);
if (op + lastRun + 1 + (lastRun-RUN_MASK+255)/255 > oend) return 0;
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun > 254 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
- else *op++ = (lastRun<<ML_BITS);
+ else *op++ = (BYTE)(lastRun<<ML_BITS);
memcpy(op, anchor, iend - anchor);
op += iend-anchor;
}
@@ -680,6 +681,7 @@ int LZ4_compress_limitedOutput(const char* source,
#if HEAPMODE
void* ctx = malloc(sizeof(struct refTables));
int result;
+ if (ctx == NULL) return 0; // Failed allocation => compression not done
if (isize < LZ4_64KLIMIT)
result = LZ4_compress64kCtx(&ctx, source, dest, isize, maxOutputSize);
else result = LZ4_compressCtx(&ctx, source, dest, isize, maxOutputSize);
@@ -729,7 +731,7 @@ int LZ4_uncompress(const char* source,
size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0};
#if LZ4_ARCH64
- size_t dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3};
+ size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3};
#endif
@@ -817,7 +819,7 @@ int LZ4_uncompress_unknownOutputSize(
size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0};
#if LZ4_ARCH64
- size_t dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3};
+ size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3};
#endif