Skip to content

Idiomatic c demangle #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions crates/native-c/src/demangle.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Code for demangling Rust symbols. This code is mostly
// a line-by-line translation of the Rust code in `rustc-demangle`.

// you can find the latest version of this code in https://github.com/rust-lang/rustc-demangle

#include <stdint.h>
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -1707,10 +1709,8 @@ NODISCARD static demangle_status rust_demangle_legacy_demangle(const char *s, si
if (chars_len == 0) {
return DemangleInvalid;
}
char c = *chars++;
chars_len--;

while (c != 'E') {
char c;
while ((c = *chars) != 'E') {
// Decode an identifier element's length
if (c < '0' || c > '9') {
return DemangleInvalid;
Expand All @@ -1726,25 +1726,25 @@ NODISCARD static demangle_status rust_demangle_legacy_demangle(const char *s, si
return DemangleInvalid;
}
len += d;

chars++;
chars_len--;
if (chars_len == 0) {
return DemangleInvalid;
}
c = *chars++;
chars_len--;
c = *chars;
}

// Advance by the length
for (size_t i = 0; i < len; i++) {
if (chars_len == 0) {
return DemangleInvalid;
}
c = *chars++;
chars_len--;
if (chars_len <= len) {
return DemangleInvalid;
}
chars += len;
chars_len -= len;
elements++;
}
*res = (struct demangle_legacy) { inner, inner_len, elements };
*rest = chars;
*rest = chars + 1;
return DemangleOk;
}

Expand Down
Loading