74 /* check and forward error code */ |
74 /* check and forward error code */ |
75 #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; } |
75 #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; } |
76 |
76 |
77 |
77 |
78 /* ************************************************************** |
78 /* ************************************************************** |
79 * Complex types |
|
80 ****************************************************************/ |
|
81 typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)]; |
|
82 |
|
83 |
|
84 /* ************************************************************** |
|
85 * Templates |
79 * Templates |
86 ****************************************************************/ |
80 ****************************************************************/ |
87 /* |
81 /* |
88 designed to be included |
82 designed to be included |
89 for type-specific functions (template emulation in C) |
83 for type-specific functions (template emulation in C) |
298 if (fastMode) return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 1); |
292 if (fastMode) return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 1); |
299 return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 0); |
293 return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 0); |
300 } |
294 } |
301 |
295 |
302 |
296 |
303 size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize) |
297 size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog) |
304 { |
298 { |
305 const BYTE* const istart = (const BYTE*)cSrc; |
299 const BYTE* const istart = (const BYTE*)cSrc; |
306 const BYTE* ip = istart; |
300 const BYTE* ip = istart; |
307 short counting[FSE_MAX_SYMBOL_VALUE+1]; |
301 short counting[FSE_MAX_SYMBOL_VALUE+1]; |
308 DTable_max_t dt; /* Static analyzer seems unable to understand this table will be properly initialized later */ |
|
309 unsigned tableLog; |
302 unsigned tableLog; |
310 unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE; |
303 unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE; |
311 |
304 |
312 if (cSrcSize<2) return ERROR(srcSize_wrong); /* too small input size */ |
|
313 |
|
314 /* normal FSE decoding mode */ |
305 /* normal FSE decoding mode */ |
315 { size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize); |
306 size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize); |
316 if (FSE_isError(NCountLength)) return NCountLength; |
307 if (FSE_isError(NCountLength)) return NCountLength; |
317 if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size */ |
308 //if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */ |
318 ip += NCountLength; |
309 if (tableLog > maxLog) return ERROR(tableLog_tooLarge); |
319 cSrcSize -= NCountLength; |
310 ip += NCountLength; |
320 } |
311 cSrcSize -= NCountLength; |
321 |
312 |
322 CHECK_F( FSE_buildDTable (dt, counting, maxSymbolValue, tableLog) ); |
313 CHECK_F( FSE_buildDTable (workSpace, counting, maxSymbolValue, tableLog) ); |
323 |
314 |
324 return FSE_decompress_usingDTable (dst, maxDstSize, ip, cSrcSize, dt); /* always return, even if it is an error code */ |
315 return FSE_decompress_usingDTable (dst, dstCapacity, ip, cSrcSize, workSpace); /* always return, even if it is an error code */ |
|
316 } |
|
317 |
|
318 |
|
319 typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)]; |
|
320 |
|
321 size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize) |
|
322 { |
|
323 DTable_max_t dt; /* Static analyzer seems unable to understand this table will be properly initialized later */ |
|
324 return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, dt, FSE_MAX_TABLELOG); |
325 } |
325 } |
326 |
326 |
327 |
327 |
328 |
328 |
329 #endif /* FSE_COMMONDEFS_ONLY */ |
329 #endif /* FSE_COMMONDEFS_ONLY */ |