@@ -85,7 +85,6 @@ static const size_t hash_prefix_len = 3;
85
85
static const size_t hash_len = 16 ;
86
86
87
87
static int is_prefixed_hash (const char * start );
88
- static int looks_like_rust (const char * sym , size_t len );
89
88
static int parse_lower_hex_nibble (char nibble );
90
89
static char parse_legacy_escape (const char * * in );
91
90
@@ -105,16 +104,13 @@ static char parse_legacy_escape (const char **in);
105
104
negative (the rare Rust symbol is not demangled) so this sets
106
105
the balance in favor of false negatives.
107
106
108
- 3. There must be no characters other than a-zA-Z0-9 and _.:$
109
-
110
- 4. There must be no unrecognized $-sign sequences.
111
-
112
- 5. There must be no sequence of three or more dots in a row ("..."). */
107
+ 3. There must be no characters other than a-zA-Z0-9 and _.:$ */
113
108
114
109
int
115
110
rust_is_mangled (const char * sym )
116
111
{
117
112
size_t len , len_without_hash ;
113
+ const char * end ;
118
114
119
115
if (!sym )
120
116
return 0 ;
@@ -128,12 +124,22 @@ rust_is_mangled (const char *sym)
128
124
if (!is_prefixed_hash (sym + len_without_hash ))
129
125
return 0 ;
130
126
131
- return looks_like_rust (sym , len_without_hash );
127
+ end = sym + len_without_hash ;
128
+
129
+ while (sym < end )
130
+ {
131
+ if (* sym == '$' || * sym == '.' || * sym == '_' || * sym == ':'
132
+ || ISALNUM (* sym ))
133
+ sym ++ ;
134
+ else
135
+ return 0 ;
136
+ }
137
+
138
+ return 1 ;
132
139
}
133
140
134
141
/* A hash is the prefix "::h" followed by 16 lowercase hex digits. The
135
- hex digits must comprise between 5 and 15 (inclusive) distinct
136
- digits. */
142
+ hex digits must contain at least 5 distinct digits. */
137
143
138
144
static int
139
145
is_prefixed_hash (const char * str )
@@ -162,28 +168,7 @@ is_prefixed_hash (const char *str)
162
168
if (seen [i ])
163
169
count ++ ;
164
170
165
- return count >= 5 && count <= 15 ;
166
- }
167
-
168
- static int
169
- looks_like_rust (const char * str , size_t len )
170
- {
171
- const char * end = str + len ;
172
-
173
- while (str < end )
174
- {
175
- if (* str == '$' )
176
- {
177
- if (!parse_legacy_escape (& str ))
178
- return 0 ;
179
- }
180
- else if (* str == '.' || * str == '_' || * str == ':' || ISALNUM (* str ))
181
- str ++ ;
182
- else
183
- return 0 ;
184
- }
185
-
186
- return 1 ;
171
+ return count >= 5 ;
187
172
}
188
173
189
174
/*
@@ -215,8 +200,9 @@ rust_demangle_sym (char *sym)
215
200
if (unescaped )
216
201
* out ++ = unescaped ;
217
202
else
218
- /* unexpected escape sequence, not looks_like_rust. */
219
- goto fail ;
203
+ /* unexpected escape sequence, skip the rest of this segment. */
204
+ while (in < end && * in != ':' )
205
+ * out ++ = * in ++ ;
220
206
}
221
207
else if (* in == '_' )
222
208
{
@@ -248,14 +234,14 @@ rust_demangle_sym (char *sym)
248
234
else if (* in == ':' || ISALNUM (* in ))
249
235
* out ++ = * in ++ ;
250
236
else
251
- /* unexpected character in symbol, not looks_like_rust. */
252
- goto fail ;
237
+ {
238
+ /* unexpected character in symbol, not rust_is_mangled. */
239
+ * out ++ = '?' ; /* This is pretty lame, but it's hard to do better. */
240
+ * out = '\0' ;
241
+ return ;
242
+ }
253
243
}
254
- goto done ;
255
244
256
- fail :
257
- * out ++ = '?' ; /* This is pretty lame, but it's hard to do better. */
258
- done :
259
245
* out = '\0' ;
260
246
}
261
247
0 commit comments