#include <stddef.h> /* size_t */
#include <stdlib.h> /* malloc, free, abort */
#include <stdio.h> /* fprintf */
+#include <limits.h> /* UINT_MAX */
#include <assert.h> /* assert */
#include "util.h"
static buffer_t
createDictionaryBuffer(const char* dictionaryName,
const void* srcBuffer,
- const size_t* srcBlockSizes, unsigned nbBlocks,
+ const size_t* srcBlockSizes, size_t nbBlocks,
size_t requestedDictSize)
{
if (dictionaryName) {
void* const dictBuffer = malloc(requestedDictSize);
CONTROL(dictBuffer != NULL);
+ assert(nbBlocks <= UINT_MAX);
size_t const dictSize = ZDICT_trainFromBuffer(dictBuffer, requestedDictSize,
srcBuffer,
- srcBlockSizes, nbBlocks);
+ srcBlockSizes, (unsigned)nbBlocks);
CONTROL(!ZSTD_isError(dictSize));
buffer_t result;
size_t const initResult = ZSTD_seekable_initFile(seekable, fin);
if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_seekable_init() error : %s \n", ZSTD_getErrorName(initResult)); exit(11); }
- size_t const numFrames = ZSTD_seekable_getNumFrames(seekable);
+ unsigned const numFrames = ZSTD_seekable_getNumFrames(seekable);
struct sum_job* jobs = (struct sum_job*)malloc(numFrames * sizeof(struct sum_job));
- size_t i;
- for (i = 0; i < numFrames; i++) {
- jobs[i] = (struct sum_job){ fname, 0, i, 0 };
- POOL_add(pool, sumFrame, &jobs[i]);
+ unsigned fnb;
+ for (fnb = 0; fnb < numFrames; fnb++) {
+ jobs[fnb] = (struct sum_job){ fname, 0, fnb, 0 };
+ POOL_add(pool, sumFrame, &jobs[fnb]);
}
unsigned long long total = 0;
- for (i = 0; i < numFrames; i++) {
- while (!jobs[i].done) SLEEP(5); /* wake up every 5 milliseconds to check */
- total += jobs[i].sum;
+ for (fnb = 0; fnb < numFrames; fnb++) {
+ while (!jobs[fnb].done) SLEEP(5); /* wake up every 5 milliseconds to check */
+ total += jobs[fnb].sum;
}
printf("Sum: %llu\n", total);
*/
#include <stdlib.h> /* malloc, free */
+#include <limits.h> /* UINT_MAX */
+#include <assert.h>
#define XXH_STATIC_LINKING_ONLY
#define XXH_NAMESPACE ZSTD_
}
size_t ZSTD_seekable_logFrame(ZSTD_frameLog* fl,
- unsigned compressedSize,
- unsigned decompressedSize,
- unsigned checksum)
+ unsigned compressedSize,
+ unsigned decompressedSize,
+ unsigned checksum)
{
if (fl->size == ZSTD_SEEKABLE_MAXFRAMES)
return ERROR(frameIndex_tooLarge);
if (newEntries == NULL) return ERROR(memory_allocation);
fl->entries = newEntries;
- fl->capacity = newCapacity;
+ assert(newCapacity <= UINT_MAX);
+ fl->capacity = (U32)newCapacity;
}
fl->entries[fl->size] = (framelogEntry_t){
size_t const seekTableLen = ZSTD_seekable_seekTableSize(fl);
CHECK_Z(ZSTD_stwrite32(fl, output, ZSTD_MAGIC_SKIPPABLE_START | 0xE, 0));
- CHECK_Z(ZSTD_stwrite32(fl, output, seekTableLen - ZSTD_SKIPPABLEHEADERSIZE,
- 4));
+ assert(seekTableLen <= (size_t)UINT_MAX);
+ CHECK_Z(ZSTD_stwrite32(fl, output, (U32)seekTableLen - ZSTD_SKIPPABLEHEADERSIZE, 4));
while (fl->seekTableIndex < fl->size) {
+ unsigned long long const start = ZSTD_SKIPPABLEHEADERSIZE + sizePerFrame * fl->seekTableIndex;
+ assert(start + 8 <= UINT_MAX);
CHECK_Z(ZSTD_stwrite32(fl, output,
fl->entries[fl->seekTableIndex].cSize,
- ZSTD_SKIPPABLEHEADERSIZE +
- sizePerFrame * fl->seekTableIndex + 0));
+ (U32)start + 0));
CHECK_Z(ZSTD_stwrite32(fl, output,
fl->entries[fl->seekTableIndex].dSize,
- ZSTD_SKIPPABLEHEADERSIZE +
- sizePerFrame * fl->seekTableIndex + 4));
+ (U32)start + 4));
if (fl->checksumFlag) {
CHECK_Z(ZSTD_stwrite32(
fl, output, fl->entries[fl->seekTableIndex].checksum,
- ZSTD_SKIPPABLEHEADERSIZE +
- sizePerFrame * fl->seekTableIndex + 8));
+ (U32)start + 8));
}
fl->seekTableIndex++;
}
+ assert(seekTableLen <= UINT_MAX);
CHECK_Z(ZSTD_stwrite32(fl, output, fl->size,
- seekTableLen - ZSTD_seekTableFooterSize));
+ (U32)seekTableLen - ZSTD_seekTableFooterSize));
if (output->size - output->pos < 1) return seekTableLen - fl->seekTablePos;
if (fl->seekTablePos < seekTableLen - 4) {
}
CHECK_Z(ZSTD_stwrite32(fl, output, ZSTD_SEEKABLE_MAGICNUMBER,
- seekTableLen - 4));
+ (U32)seekTableLen - 4));
if (fl->seekTablePos != seekTableLen) return ERROR(GENERIC);
return 0;
# define LONG_SEEK fseek
#endif
-#include <stdlib.h> /* malloc, free */
-#include <stdio.h> /* FILE* */
+#include <stdlib.h> /* malloc, free */
+#include <stdio.h> /* FILE* */
+#include <limits.h> /* UNIT_MAX */
#include <assert.h>
#define XXH_STATIC_LINKING_ONLY
U32 ZSTD_seekable_offsetToFrameIndex(ZSTD_seekable* const zs, unsigned long long pos)
{
U32 lo = 0;
- U32 hi = zs->seekTable.tableLen;
+ U32 hi = (U32)zs->seekTable.tableLen;
+ assert(zs->seekTable.tableLen <= UINT_MAX);
if (pos >= zs->seekTable.entries[zs->seekTable.tableLen].dOffset) {
- return zs->seekTable.tableLen;
+ return (U32)zs->seekTable.tableLen;
}
while (lo + 1 < hi) {
U32 ZSTD_seekable_getNumFrames(ZSTD_seekable* const zs)
{
- return zs->seekTable.tableLen;
+ assert(zs->seekTable.tableLen <= UINT_MAX);
+ return (U32)zs->seekTable.tableLen;
}
unsigned long long ZSTD_seekable_getFrameCompressedOffset(ZSTD_seekable* const zs, U32 frameIndex)
* It helps preserve compression ratio, while each job is compressed in parallel.
* This value is enforced only when nbWorkers >= 1.
* Larger values increase compression ratio, but decrease speed.
- * Values range from 0 to 9 (overlap a full windowSize).
- * - 0 means "auto" : value will be determined by the library, depending on strategy
+ * Possible values range from 0 to 9 :
+ * - 0 means "default" : value will be determined by the library, depending on strategy
* - 1 means "no overlap"
* - 9 means "full overlap", using a full window size.
* Each intermediate rank increases/decreases load size by a factor 2 :
- * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:auto
+ * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:default
* default value varies between 6 and 9, depending on strategy */
</b>/* note : additional experimental parameters are also available<b>
/*-*************************************
* Dependencies
***************************************/
+#include <limits.h> /* INT_MAX */
#include <string.h> /* memset */
#include "cpu.h"
#include "mem.h"
#ifndef ZSTD_MULTITHREAD
return ERROR(parameter_unsupported);
#else
- *value = CCtxParams->jobSize;
+ assert(CCtxParams->jobSize <= INT_MAX);
+ *value = (int)CCtxParams->jobSize;
break;
#endif
case ZSTD_c_overlapLog :
/* ====== Dependencies ====== */
#include <string.h> /* memcpy, memset */
-#include <limits.h> /* INT_MAX */
+#include <limits.h> /* INT_MAX, UINT_MAX */
#include "pool.h" /* threadpool */
#include "threading.h" /* mutex */
#include "zstd_compress_internal.h" /* MIN, ERROR, ZSTD_*, ZSTD_highbit32 */
if (value < ZSTDMT_JOBSIZE_MIN) value = ZSTDMT_JOBSIZE_MIN;
assert(value >= 0);
{ size_t jobSize = value;
- if (jobSize > ZSTDMT_JOBSIZE_MAX) jobSize = ZSTDMT_JOBSIZE_MAX;
+ if (jobSize > (size_t)ZSTDMT_JOBSIZE_MAX) jobSize = ZSTDMT_JOBSIZE_MAX;
params->jobSize = jobSize;
return jobSize;
}
{
switch (parameter) {
case ZSTDMT_p_jobSize:
- *value = mtctx->params.jobSize;
+ assert(mtctx->params.jobSize <= UINT_MAX);
+ *value = (unsigned)(mtctx->params.jobSize);
break;
case ZSTDMT_p_overlapLog:
*value = mtctx->params.overlapLog;
/* ===== Multi-threaded compression ===== */
/* ------------------------------------------ */
-static size_t ZSTDMT_computeTargetJobLog(ZSTD_CCtx_params const params)
+static unsigned ZSTDMT_computeTargetJobLog(ZSTD_CCtx_params const params)
{
if (params.ldmParams.enableLdm)
/* In Long Range Mode, the windowLog is typically oversized.
CHECK_F( ZSTDMT_resize(mtctx, params.nbWorkers) );
if (params.jobSize > 0 && params.jobSize < ZSTDMT_JOBSIZE_MIN) params.jobSize = ZSTDMT_JOBSIZE_MIN;
- if (params.jobSize > ZSTDMT_JOBSIZE_MAX) params.jobSize = ZSTDMT_JOBSIZE_MAX;
+ if (params.jobSize > (size_t)ZSTDMT_JOBSIZE_MAX) params.jobSize = ZSTDMT_JOBSIZE_MAX;
mtctx->singleBlockingThread = (pledgedSrcSize <= ZSTDMT_JOBSIZE_MIN); /* do not trigger multi-threading when srcSize is too small */
if (mtctx->singleBlockingThread) {
#ifndef ZSTDMT_JOBSIZE_MIN
# define ZSTDMT_JOBSIZE_MIN (1 MB)
#endif
-#define ZSTDMT_JOBSIZE_MAX ((size_t)(MEM_32bits() ? (512 MB) : (1 GB)))
+#define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))
/* === Memory management === */