mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
Fix undefined behaviour
Just use stat and opendir. Fixes #228. While here correct the error message.
This commit is contained in:
parent
a742a5fb8b
commit
55f336751d
@ -146,9 +146,8 @@ bool isIgnorable(const std::string &f) {
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
||||||
// Is our input path a file or a directory?
|
// Is our input path a file or a directory?
|
||||||
int fd = open(inPath.c_str(), O_RDONLY);
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstat(fd, &st) != 0) {
|
if (stat(inPath.c_str(), &st) != 0) {
|
||||||
cerr << "Can't stat path: '" << inPath << "'" << endl;
|
cerr << "Can't stat path: '" << inPath << "'" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -161,7 +160,7 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else if (S_ISDIR(st.st_mode)) {
|
} else if (S_ISDIR(st.st_mode)) {
|
||||||
DIR *d = fdopendir(fd);
|
DIR *d = opendir(inPath.c_str());
|
||||||
if (d == nullptr) {
|
if (d == nullptr) {
|
||||||
cerr << "Can't open directory: '" << inPath << "'" << endl;
|
cerr << "Can't open directory: '" << inPath << "'" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -192,10 +191,11 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
|||||||
}
|
}
|
||||||
(void)closedir(d);
|
(void)closedir(d);
|
||||||
} else {
|
} else {
|
||||||
cerr << "Can't stat path: '" << inPath << "'" << endl;
|
cerr << "Unsupported file type "
|
||||||
|
<< hex << showbase << (st.st_mode & S_IFMT)
|
||||||
|
<< " for path: '" << inPath << "'" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
(void)close(fd);
|
|
||||||
}
|
}
|
||||||
#else // windows TODO: improve
|
#else // windows TODO: improve
|
||||||
void HS_CDECL loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
void HS_CDECL loadExpressions(const string &inPath, ExpressionMap &exprMap) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user