From ab1f1f8360f77c3286b92f100b37b63b9bb28d0a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 31 Mar 2021 14:18:36 -0700 Subject: [PATCH] Improve detail::script_specific_filename() - To handle relative paths that don't start with a '.' - To handle getcwd() failures --- src/script_opt/ProfileFunc.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index e65286364c..514a10447c 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -29,16 +29,19 @@ std::string script_specific_filename(const StmtPtr& body) auto bl_f = body_loc->filename; ASSERT(bl_f != nullptr); - if ( bl_f[0] == '.' && - (bl_f[1] == '/' || (bl_f[1] == '.' && bl_f[2] == '/')) ) + if ( (bl_f[0] != '.' && bl_f[0] != '/') || + (bl_f[0] == '.' && (bl_f[1] == '/' || + (bl_f[1] == '.' && bl_f[2] == '/'))) ) { // Add working directory to avoid collisions over the // same relative name. static std::string working_dir; - if ( working_dir.size() == 0 ) + if ( working_dir.empty() ) { char buf[8192]; - getcwd(buf, sizeof buf); + if ( ! getcwd(buf, sizeof buf) ) + reporter->InternalError("getcwd failed: %s", strerror(errno)); + working_dir = buf; }