Skip to content

Commit ed7b761

Browse files
powerboat9P-E-P
authored andcommitted
Remove undefined behavior with static_cast
gcc/rust/ChangeLog: * expand/rust-macro-builtins-helpers.cc (try_extract_string_literal_from_fragment): Perform static_cast to AST::LiteralExpr only after it's verified that an AST::Expr is a literal. Signed-off-by: Owen Avery <[email protected]>
1 parent bc03f6e commit ed7b761

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

gcc/rust/expand/rust-macro-builtins-helpers.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ std::unique_ptr<AST::LiteralExpr>
111111
try_extract_string_literal_from_fragment (const location_t &parent_locus,
112112
std::unique_ptr<AST::Expr> &node)
113113
{
114-
auto maybe_lit = static_cast<AST::LiteralExpr *> (node.get ());
115114
if (!node || !node->is_literal ()
116-
|| maybe_lit->get_lit_type () != AST::Literal::STRING)
115+
|| static_cast<AST::LiteralExpr &> (*node).get_lit_type ()
116+
!= AST::Literal::STRING)
117117
{
118118
rust_error_at (parent_locus, "argument must be a string literal");
119119
if (node)

0 commit comments

Comments
 (0)