Skip to content

Commit 8ee5b71

Browse files
author
Pascal Menuet
committed
Try fixing exceptions stuff accordingly to comments in microsoft#30 and microsoft#36
1 parent ec08ed7 commit 8ee5b71

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.vs/
12
/build/
23
/prefix/
34
/linux-build/

include/ifc/abstract-sgraph.hxx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,18 @@ namespace ifc {
35443544

35453545
// -- exception type in case of an invalid partition name
35463546
struct InvalidPartitionName {
3547-
std::string_view name;
3547+
static constexpr unsigned NAME_BUFFER_SIZE = 64;
3548+
3549+
char name[NAME_BUFFER_SIZE] = "";
3550+
3551+
static InvalidPartitionName make(std::string_view name) noexcept
3552+
{
3553+
InvalidPartitionName e{};
3554+
name = name.substr(0, NAME_BUFFER_SIZE - 1);
3555+
strncpy_s(e.name, name.data(), name.length());
3556+
e.name[name.length()] = 0;
3557+
return e;
3558+
}
35483559
};
35493560

35503561
// Retrieve a partition summary based on the partition's name.

src/ifc-printer/main.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ void translate_exception()
1818
{
1919
std::cerr << "ifc architecture mismatch\n";
2020
}
21-
catch(ifc::error_condition::UnexpectedVisitor& e)
21+
catch (const ifc::InvalidPartitionName& e)
22+
{
23+
std::cerr << "invalid partition name: " << e.name << '\n';
24+
}
25+
catch (ifc::error_condition::UnexpectedVisitor& e)
2226
{
2327
std::cerr << "visit unexpected " << e.category << ": "
2428
<< e.sort << '\n';
2529
}
26-
catch (const char* message)
30+
catch (const std::logic_error& e)
2731
{
28-
std::cerr << "caught: " << message;
32+
std::cerr << "caught: " << e.what();
2933
}
3034
catch (...)
3135
{
@@ -112,6 +116,8 @@ void process_ifc(const std::string& name, PrintOptions options)
112116
file.validate<ifc::UnitSort::Primary>(path, ifc::Architecture::Unknown, ifc::Pathname{},
113117
ifc::IfcOptions::IntegrityCheck);
114118

119+
if (not file.header())
120+
throw std::logic_error{"file not found"};
115121
ifc::Reader reader(file);
116122
ifc::util::Loader loader(reader);
117123
auto& gs = loader.get(reader.ifc.header()->global_scope);

src/ifc-reader/reader.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
#include "ifc/util.hxx"
55
#include "ifc/reader.hxx"
6+
#include <cassert>
67

78
namespace ifc {
89
constexpr std::string_view analysis_partition_prefix = ".msvc.code-analysis.";
910

1011
Reader::Reader(const ifc::InputIfc& ifc_) : ifc(ifc_)
1112
{
12-
if (not ifc.header())
13-
throw "file not found";
13+
assert(ifc.header());
1414
read_table_of_contents();
1515
}
1616

src/sgraph.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ namespace ifc {
546546
{
547547
auto p = table.find(name);
548548
if (p == table.end())
549-
throw InvalidPartitionName{name};
549+
throw InvalidPartitionName::make(name);
550550
return p->sort;
551551
}
552552

0 commit comments

Comments
 (0)