From e82713764741d9e6448196d39373bd839d9f4fd0 Mon Sep 17 00:00:00 2001
From: XLS Team
Date: Wed, 2 Oct 2024 13:17:39 -0700
Subject: [PATCH] Fix a use-after-free bug in
xls/visualization/sched_printer_main.cc.
PiperOrigin-RevId: 681567169
---
xls/visualization/sched_printer_main.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/xls/visualization/sched_printer_main.cc b/xls/visualization/sched_printer_main.cc
index 469b2f1e55..27f5827ef1 100644
--- a/xls/visualization/sched_printer_main.cc
+++ b/xls/visualization/sched_printer_main.cc
@@ -347,8 +347,10 @@ absl::Status RealMain(std::string_view ir_path) {
XLS_RETURN_IF_ERROR(VerifyPackage(p.get()));
std::string top_str = absl::GetFlag(FLAGS_top);
- std::optional maybe_top_str =
- top_str.empty() ? std::nullopt : std::make_optional(top_str);
+ std::optional maybe_top_str;
+ if (!top_str.empty()) {
+ maybe_top_str = top_str;
+ }
XLS_ASSIGN_OR_RETURN(FunctionBase * main, FindTop(p.get(), maybe_top_str));
XLS_ASSIGN_OR_RETURN(