mirror of
https://github.com/facebook/zstd.git
synced 2025-07-29 11:21:22 +03:00
fixed more issues detected by recent version of scan-build
test run on Linux
This commit is contained in:
@ -73,7 +73,11 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
|
||||
ZSTD_CStream* const cstream = ZSTD_createCStream();
|
||||
if (cstream==NULL) { fprintf(stderr, "ZSTD_createCStream() error \n"); exit(10); }
|
||||
size_t const initResult = ZSTD_initCStream(cstream, cLevel);
|
||||
if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_initCStream() error : %s \n", ZSTD_getErrorName(initResult)); exit(11); }
|
||||
if (ZSTD_isError(initResult)) {
|
||||
fprintf(stderr, "ZSTD_initCStream() error : %s \n",
|
||||
ZSTD_getErrorName(initResult));
|
||||
exit(11);
|
||||
}
|
||||
|
||||
size_t read, toRead = buffInSize;
|
||||
while( (read = fread_orDie(buffIn, toRead, fin)) ) {
|
||||
@ -81,7 +85,11 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
|
||||
while (input.pos < input.size) {
|
||||
ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
|
||||
toRead = ZSTD_compressStream(cstream, &output , &input); /* toRead is guaranteed to be <= ZSTD_CStreamInSize() */
|
||||
if (ZSTD_isError(toRead)) { fprintf(stderr, "ZSTD_compressStream() error : %s \n", ZSTD_getErrorName(toRead)); exit(12); }
|
||||
if (ZSTD_isError(toRead)) {
|
||||
fprintf(stderr, "ZSTD_compressStream() error : %s \n",
|
||||
ZSTD_getErrorName(toRead));
|
||||
exit(12);
|
||||
}
|
||||
if (toRead > buffInSize) toRead = buffInSize; /* Safely handle case when `buffInSize` is manually changed to a value < ZSTD_CStreamInSize()*/
|
||||
fwrite_orDie(buffOut, output.pos, fout);
|
||||
}
|
||||
@ -100,15 +108,15 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
|
||||
}
|
||||
|
||||
|
||||
static const char* createOutFilename_orDie(const char* filename)
|
||||
static char* createOutFilename_orDie(const char* filename)
|
||||
{
|
||||
size_t const inL = strlen(filename);
|
||||
size_t const outL = inL + 5;
|
||||
void* outSpace = malloc_orDie(outL);
|
||||
void* const outSpace = malloc_orDie(outL);
|
||||
memset(outSpace, 0, outL);
|
||||
strcat(outSpace, filename);
|
||||
strcat(outSpace, ".zst");
|
||||
return (const char*)outSpace;
|
||||
return (char*)outSpace;
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
@ -124,8 +132,10 @@ int main(int argc, const char** argv)
|
||||
|
||||
const char* const inFilename = argv[1];
|
||||
|
||||
const char* const outFilename = createOutFilename_orDie(inFilename);
|
||||
char* const outFilename = createOutFilename_orDie(inFilename);
|
||||
compressFile_orDie(inFilename, outFilename, 1);
|
||||
|
||||
free(outFilename); /* not strictly required, since program execution stops there,
|
||||
* but some static analyzer main complain otherwise */
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user