Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dsm/DSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ bool DSMFactory::loadDiags(AmConfigReader& cfg, DSMStateDiagramCollection* m_dia
for (vector<string>::iterator it=
diags_names.begin(); it != diags_names.end(); it++) {
if (!m_diags->loadFile(DiagPath+*it+".dsm", *it, DiagPath, ModPath, DebugDSM, CheckDSM)) {
ERROR("loading %s from %s\n",
ERROR("loading diagram '%s' from '%s' failed\n",
it->c_str(), (DiagPath+*it+".dsm").c_str());
ERROR(" Check that diag_path='%s' is correct and '%s' is readable by the SEMS process\n",
DiagPath.c_str(), (DiagPath+*it+".dsm").c_str());
return false;
}
}
Expand Down
20 changes: 17 additions & 3 deletions apps/dsm/DSMStateDiagramCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <fstream>
using std::ifstream;

#include <cerrno>
#include <dirent.h>

DSMStateDiagramCollection::DSMStateDiagramCollection() {
Expand All @@ -44,8 +45,16 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n

ifstream ifs(filename.c_str());
if (!ifs.good()) {
ERROR("loading state diagram '%s'\n",
filename.c_str());
ERROR("loading state diagram '%s': cannot open file (%s)\n",
filename.c_str(), strerror(errno));

// Check if the user forgot the .dsm extension (common #include mistake)
string with_ext = filename + ".dsm";
ifstream test_ifs(with_ext.c_str());
if (test_ifs.good()) {
ERROR(" Hint: '%s' exists - did you mean to use '%s' in your #include directive?\n",
with_ext.c_str(), with_ext.c_str());
Comment on lines +48 to +56
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errno value may not be reliable after an ifstream constructor or good() call fails. C++ iostream operations do not guarantee that errno is set on failure. The strerror(errno) call may report a stale or incorrect error code. Consider using failbit and checking specific failure modes, or save errno immediately after operations that are guaranteed to set it (like open() syscalls), rather than relying on errno after iostream operations.

Suggested change
ERROR("loading state diagram '%s': cannot open file (%s)\n",
filename.c_str(), strerror(errno));
// Check if the user forgot the .dsm extension (common #include mistake)
string with_ext = filename + ".dsm";
ifstream test_ifs(with_ext.c_str());
if (test_ifs.good()) {
ERROR(" Hint: '%s' exists - did you mean to use '%s' in your #include directive?\n",
with_ext.c_str(), with_ext.c_str());
ERROR("loading state diagram '%s': cannot open file\n",
filename.c_str());
// Check if the user forgot the .dsm extension (common #include mistake)
string with_ext = filename + ".dsm";
ifstream test_ifs(with_ext.c_str());
if (test_ifs.good()) {
ERROR(" Hint: '%s' exists - did you mean to use '%s' in your #include directive?\n",
with_ext.c_str(), with_ext.c_str());

Copilot uses AI. Check for mistakes.
}
return false;
}

Expand Down Expand Up @@ -92,6 +101,8 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
if (name.rfind(".dsm") != (name.size() - 4)) continue;
include_dir_name = include_name + "/" + name;
if (!readFile(include_dir_name, name, current_load_path, s)) {
ERROR(" while processing '#include %s' (directory entry '%s') in '%s'\n",
include_name.c_str(), include_dir_name.c_str(), filename.c_str());
(void)closedir(dp);
return false;
}
Expand All @@ -102,8 +113,11 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
return false;
}
} else {
if (!readFile(include_name, name, current_load_path, s))
if (!readFile(include_name, name, current_load_path, s)) {
ERROR(" while processing '#include %s' in '%s'\n",
include_name.c_str(), filename.c_str());
return false;
}
}
continue;
}
Expand Down