Skip to content

Commit 6528d7d

Browse files
cblichmanncopybara-github
authored andcommitted
Initialize errno properly before string parsing, fix save filename
PiperOrigin-RevId: 377498965 Change-Id: Ib3b02b53f75b79a788c99cbe032a1142230ee496
1 parent 5c8c9aa commit 6528d7d

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

ida/main_plugin.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,14 @@ bool DoSaveResults() {
748748

749749
try {
750750
auto* results = Plugin::instance()->results();
751+
// If we have loaded results, input_filename_ will be non-empty.
752+
const std::string default_filename =
753+
results->input_filename_.empty()
754+
? absl::StrCat(results->call_graph1_.GetFilename(), "_vs_",
755+
results->call_graph2_.GetFilename(), ".BinDiff")
756+
: results->input_filename_;
751757
const char* filename = ask_file(
752-
/*for_saving=*/true, results->input_filename_.c_str(), "%s",
758+
/*for_saving=*/true, default_filename.c_str(), "%s",
753759
absl::StrCat("FILTER BinDiff Result files|*.BinDiff|All files",
754760
kAllFilesFilter, "\nSave Results As")
755761
.c_str());

match_colors.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ absl::optional<int64_t> HexColorToInt(absl::string_view value) {
3535
if (color_string.size() != 6) {
3636
return absl::nullopt;
3737
}
38+
errno = 0;
3839
uint64_t v = std::strtoul( // NOLINT(runtime/deprecated_fn)
3940
color_string.c_str(), nullptr, 16);
4041
if (errno == ERANGE) {
@@ -67,25 +68,25 @@ uint32_t GetMatchColor(double value) {
6768
}();
6869

6970
static auto* color_ramp = []() -> std::vector<uint32_t>* {
70-
auto* color_ramp = new std::vector<uint32_t>(
71-
ParseColorRamp(default_theme.similarity_ramp()));
71+
auto* color_ramp =
72+
new std::vector<uint32_t>(ParseColorRamp(theme.similarity_ramp()));
7273
if (color_ramp->empty() ||
7374
color_ramp->size() != theme.similarity_ramp_size()) {
74-
// Parse error, set default color ramp
75+
// Parse error, set default color ramp. This should never fail, as the
76+
// data is embedded.
7577
*color_ramp = ParseColorRamp(default_theme.similarity_ramp());
7678
}
7779
return color_ramp;
7880
}();
7981

8082
static uint32_t manual_match_color = *HexColorToInt(theme.manual_match());
8183

82-
uint32_t color;
84+
uint32_t color = 0xffffff; // Fallback to white
8385
if (value == kManualMatch) {
8486
color = manual_match_color;
85-
} else if (value >= 0.0 && value <= 1.0) {
86-
color = (*color_ramp)[static_cast<int>(value * (color_ramp->size() - 1))];
87-
} else {
88-
color = 0xffffff; // Fallback to white
87+
} else if (size_t ramp_size = color_ramp->size();
88+
ramp_size > 0 && value >= 0.0 && value <= 1.0) {
89+
color = (*color_ramp)[static_cast<int>(value * (ramp_size - 1))];
8990
}
9091
return (color << 16) | (color & 0xff00) | (color >> 16);
9192
}

0 commit comments

Comments
 (0)