From b312abaa07ffdc1ba6e3d44a9bc1a8e89149c20b Mon Sep 17 00:00:00 2001 From: Rutwik Choughule Date: Thu, 3 Feb 2022 18:12:24 +0530 Subject: [PATCH] add check for filename in nvrtc_helper.h --- Common/helper_string.h | 1 + Common/nvrtc_helper.h | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Common/helper_string.h b/Common/helper_string.h index 66fb5d6a..39a1b380 100644 --- a/Common/helper_string.h +++ b/Common/helper_string.h @@ -421,6 +421,7 @@ inline char *sdkFindFilePath(const char *filename, } // File not found + printf("\nerror: sdkFindFilePath: file <%s> not found!\n", filename); return 0; } diff --git a/Common/nvrtc_helper.h b/Common/nvrtc_helper.h index 815a0372..4544b194 100644 --- a/Common/nvrtc_helper.h +++ b/Common/nvrtc_helper.h @@ -49,6 +49,11 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResult, size_t *cubinResultSize, int requiresCGheaders) { + if (!filename) { + std::cerr << "\nerror: filename is empty for compileFileToCUBIN()!\n"; + exit(1); + } + std::ifstream inputFile(filename, std::ios::in | std::ios::binary | std::ios::ate); @@ -111,7 +116,12 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul compileOptions = "--include-path="; - std::string path = sdkFindFilePath(HeaderNames, argv[0]); + char *strPath = sdkFindFilePath(HeaderNames, argv[0]); + if (!strPath) { + std::cerr << "\nerror: header file " << HeaderNames << " not found!\n"; + exit(1); + } + std::string path = strPath; if (!path.empty()) { std::size_t found = path.find(HeaderNames); path.erase(found); @@ -120,6 +130,7 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul "\nCooperativeGroups headers not found, please install it in %s " "sample directory..\n Exiting..\n", argv[0]); + exit(1); } compileOptions += path.c_str(); compileParams[numCompileOptions] = reinterpret_cast(