Skip to content

Commit 1c2c986

Browse files
author
Marshall Clow
committed
Fix undefined behavior in syntax_option_type::operator~ and match_flag_type::operator./a.out Found by UBSan
llvm-svn: 177693
1 parent eaef89b commit 1c2c986

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libcxx/include/regex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ _LIBCPP_CONSTEXPR
764764
syntax_option_type
765765
operator~(syntax_option_type __x)
766766
{
767-
return syntax_option_type(~int(__x));
767+
return syntax_option_type(~int(__x) & 0x1FF);
768768
}
769769

770770
inline _LIBCPP_INLINE_VISIBILITY
@@ -840,7 +840,7 @@ _LIBCPP_CONSTEXPR
840840
match_flag_type
841841
operator~(match_flag_type __x)
842842
{
843-
return match_flag_type(~int(__x));
843+
return match_flag_type(~int(__x) & 0x0FFF);
844844
}
845845

846846
inline _LIBCPP_INLINE_VISIBILITY

0 commit comments

Comments
 (0)