Skip to content

Commit fa9ac47

Browse files
0vercl0kmstange
authored andcommitted
Fix #17 by specifying that wrapping is OK when negating 0x8000_0000.
1 parent 206f4c1 commit fa9ac47

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,12 @@ impl<'a> ParserState<'a> {
816816
}
817817

818818
let mut i = 0;
819-
let mut ret = 0;
819+
let mut ret = 0i32;
820820
for c in self.remaining {
821821
match *c {
822822
b'@' => {
823823
self.advance(i + 1);
824-
return Ok(if neg { -(ret as i32) } else { ret as i32 });
824+
return Ok(if neg { ret.wrapping_neg() } else { ret });
825825
}
826826
b'A'..=b'P' => {
827827
ret = (ret << 4) + i32::from(c - b'A');

tests/test_basics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,17 @@ fn upstream_tests() {
860860
"`struct S & __cdecl f(void)'::`0'::`local static thread guard'{17}",
861861
);
862862
}
863+
864+
#[test]
865+
fn gh_issues() {
866+
let expect = |input, reference| {
867+
expect_with_flags(input, reference, 0x0);
868+
};
869+
870+
// panic: attempt to negate with overflow in `msvc_demangler::ParserState::read_number`:
871+
// <https://github.com/mstange/msvc-demangler-rust/issues/72>.
872+
expect(
873+
"??$TypedThrowBadVariantAccess@AEBV?$IdType@VGpuDiskCacheDawnWebGPU@gpu@@H$0?IAAAAAAA@$00$S@base@@@variant_internal@absl@@YAAEBV?$IdType@VGpuDiskCacheDawnWebGPU@gpu@@H$0?IAAAAAAA@$00$S@base@@XZ",
874+
"class base::IdType<class gpu::GpuDiskCacheDawnWebGPU,int,-2147483648,1> const & __cdecl absl::variant_internal::TypedThrowBadVariantAccess<class base::IdType<class gpu::GpuDiskCacheDawnWebGPU,int,-2147483648,1> const &>(void)"
875+
);
876+
}

0 commit comments

Comments
 (0)