Skip to content

Commit

Permalink
Initialize errno properly before string parsing, fix save filename
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 377498965
Change-Id: Ib3b02b53f75b79a788c99cbe032a1142230ee496
  • Loading branch information
cblichmann authored and copybara-github committed Jun 4, 2021
1 parent 5c8c9aa commit 6528d7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 7 additions & 1 deletion ida/main_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,14 @@ bool DoSaveResults() {

try {
auto* results = Plugin::instance()->results();
// If we have loaded results, input_filename_ will be non-empty.
const std::string default_filename =
results->input_filename_.empty()
? absl::StrCat(results->call_graph1_.GetFilename(), "_vs_",
results->call_graph2_.GetFilename(), ".BinDiff")
: results->input_filename_;
const char* filename = ask_file(
/*for_saving=*/true, results->input_filename_.c_str(), "%s",
/*for_saving=*/true, default_filename.c_str(), "%s",
absl::StrCat("FILTER BinDiff Result files|*.BinDiff|All files",
kAllFilesFilter, "\nSave Results As")
.c_str());
Expand Down
17 changes: 9 additions & 8 deletions match_colors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ absl::optional<int64_t> HexColorToInt(absl::string_view value) {
if (color_string.size() != 6) {
return absl::nullopt;
}
errno = 0;
uint64_t v = std::strtoul( // NOLINT(runtime/deprecated_fn)
color_string.c_str(), nullptr, 16);
if (errno == ERANGE) {
Expand Down Expand Up @@ -67,25 +68,25 @@ uint32_t GetMatchColor(double value) {
}();

static auto* color_ramp = []() -> std::vector<uint32_t>* {
auto* color_ramp = new std::vector<uint32_t>(
ParseColorRamp(default_theme.similarity_ramp()));
auto* color_ramp =
new std::vector<uint32_t>(ParseColorRamp(theme.similarity_ramp()));
if (color_ramp->empty() ||
color_ramp->size() != theme.similarity_ramp_size()) {
// Parse error, set default color ramp
// Parse error, set default color ramp. This should never fail, as the
// data is embedded.
*color_ramp = ParseColorRamp(default_theme.similarity_ramp());
}
return color_ramp;
}();

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

uint32_t color;
uint32_t color = 0xffffff; // Fallback to white
if (value == kManualMatch) {
color = manual_match_color;
} else if (value >= 0.0 && value <= 1.0) {
color = (*color_ramp)[static_cast<int>(value * (color_ramp->size() - 1))];
} else {
color = 0xffffff; // Fallback to white
} else if (size_t ramp_size = color_ramp->size();
ramp_size > 0 && value >= 0.0 && value <= 1.0) {
color = (*color_ramp)[static_cast<int>(value * (ramp_size - 1))];
}
return (color << 16) | (color & 0xff00) | (color >> 16);
}
Expand Down

0 comments on commit 6528d7d

Please sign in to comment.