fix Dereference of null pointer error

Signed-off-by: neng.liu <neng.liu@kyligence.io>
This commit is contained in:
liuneng1994 2022-01-19 02:50:07 +00:00 committed by neng.liu
parent 5e1e512bf2
commit 4d3bb1584d

View File

@ -53,6 +53,7 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int ACCESS_DENIED;
extern const int CANNOT_EXTRACT_TABLE_STRUCTURE;
extern const int LOGICAL_ERROR;
}
namespace
{
@ -72,7 +73,8 @@ namespace
HDFSFileInfo ls;
ls.file_info = hdfsListDirectory(fs.get(), prefix_without_globs.data(), &ls.length);
if (ls.file_info == nullptr && errno != ENOENT) { // NOLINT
if (ls.file_info == nullptr && errno != ENOENT) // NOLINT
{
// ignore file not found exception, keep throw other exception, libhdfs3 doesn't have function to get exception type, so use errno.
throw Exception(
ErrorCodes::ACCESS_DENIED, "Cannot list directory {}: {}", prefix_without_globs, String(hdfsGetLastError()));
@ -80,6 +82,8 @@ namespace
Strings result;
for (int i = 0; i < ls.length; ++i)
{
if (ls.file_info == nullptr)
throw Exception(ErrorCodes::LOGICAL_ERROR, "file_info shouldn't be null");
const String full_path = String(ls.file_info[i].mName);
const size_t last_slash = full_path.rfind('/');
const String file_name = full_path.substr(last_slash);