Skip to content

Commit b312aba

Browse files
committed
add check for filename in nvrtc_helper.h
1 parent 8f21b89 commit b312aba

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Common/helper_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ inline char *sdkFindFilePath(const char *filename,
421421
}
422422

423423
// File not found
424+
printf("\nerror: sdkFindFilePath: file <%s> not found!\n", filename);
424425
return 0;
425426
}
426427

Common/nvrtc_helper.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949

5050
void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResult,
5151
size_t *cubinResultSize, int requiresCGheaders) {
52+
if (!filename) {
53+
std::cerr << "\nerror: filename is empty for compileFileToCUBIN()!\n";
54+
exit(1);
55+
}
56+
5257
std::ifstream inputFile(filename,
5358
std::ios::in | std::ios::binary | std::ios::ate);
5459

@@ -111,7 +116,12 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul
111116

112117
compileOptions = "--include-path=";
113118

114-
std::string path = sdkFindFilePath(HeaderNames, argv[0]);
119+
char *strPath = sdkFindFilePath(HeaderNames, argv[0]);
120+
if (!strPath) {
121+
std::cerr << "\nerror: header file " << HeaderNames << " not found!\n";
122+
exit(1);
123+
}
124+
std::string path = strPath;
115125
if (!path.empty()) {
116126
std::size_t found = path.find(HeaderNames);
117127
path.erase(found);
@@ -120,6 +130,7 @@ void compileFileToCUBIN(char *filename, int argc, char **argv, char **cubinResul
120130
"\nCooperativeGroups headers not found, please install it in %s "
121131
"sample directory..\n Exiting..\n",
122132
argv[0]);
133+
exit(1);
123134
}
124135
compileOptions += path.c_str();
125136
compileParams[numCompileOptions] = reinterpret_cast<char *>(

0 commit comments

Comments
 (0)