Skip to content

Commit

Permalink
Rewrite check null bufStart, optimize strlen() and fixed FSE_readNCou…
Browse files Browse the repository at this point in the history
…nt_body_bmi2() for DYNAMIC_BMI2
  • Loading branch information
GermanAizek committed Oct 30, 2022
1 parent 43de2aa commit ee8c557
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/common/entropy_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
const void* headerBuffer, size_t hbSize)
{
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
return FSE_readNCount_body_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions programs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static size_t readLineFromFile(char* buf, size_t len, FILE* file)
assert(!feof(file));
if ( fgets(buf, (int) len, file) == NULL ) return 0;
{ size_t linelen = strlen(buf);
if (strlen(buf)==0) return 0;
if (buf[0]=='\0') return 0;
if (buf[linelen-1] == '\n') linelen--;
buf[linelen] = '\0';
return linelen+1;
Expand Down Expand Up @@ -693,8 +693,8 @@ static int UTIL_prepareFileList(const char *dirName,
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
assert(newListSize >= 0);
*bufStart = (char*)UTIL_realloc(*bufStart, (size_t)newListSize);
*bufEnd = *bufStart + newListSize;
if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
if (*bufStart != NULL) *bufEnd = *bufStart + newListSize;
else { free(path); closedir(dir); return 0; }
}
if (*bufStart + *pos + pathLength < *bufEnd) {
memcpy(*bufStart + *pos, path, pathLength + 1); /* with final \0 */
Expand Down
9 changes: 5 additions & 4 deletions programs/zstdcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ static void checkLibVersion(void)
*/
static int exeNameMatch(const char* exeName, const char* test)
{
return !strncmp(exeName, test, strlen(test)) &&
(exeName[strlen(test)] == '\0' || exeName[strlen(test)] == '.');
size_t len = strlen(test);
return !strncmp(exeName, test, len) &&
(exeName[len] == '\0' || exeName[len] == '.');
}

/*-************************************
Expand Down Expand Up @@ -1037,7 +1038,7 @@ int main(int argCount, const char* argv[])
if (longCommandWArg(&argument, "--size-hint")) { NEXT_TSIZE(srcSizeHint); continue; }
if (longCommandWArg(&argument, "--output-dir-flat")) {
NEXT_FIELD(outDirName);
if (strlen(outDirName) == 0) {
if (outDirName[0] == '\0') {
DISPLAY("error: output dir cannot be empty string (did you mean to pass '.' instead?)\n");
CLEAN_RETURN(1);
}
Expand All @@ -1053,7 +1054,7 @@ int main(int argCount, const char* argv[])
#ifdef UTIL_HAS_MIRRORFILELIST
if (longCommandWArg(&argument, "--output-dir-mirror")) {
NEXT_FIELD(outMirroredDirName);
if (strlen(outMirroredDirName) == 0) {
if (outMirroredDirName[0] == '\0') {
DISPLAY("error: output dir cannot be empty string (did you mean to pass '.' instead?)\n");
CLEAN_RETURN(1);
}
Expand Down

0 comments on commit ee8c557

Please sign in to comment.