@@ -149,15 +149,15 @@ static const AbbrevPair kSubstitutionList[] = {
149149
150150// State needed for demangling.
151151typedef struct {
152- const char *mangled_cur; // Cursor of mangled name.
153- char *out_cur; // Cursor of output string.
154- const char *out_begin; // Beginning of output string.
155- const char *out_end; // End of output string.
156- const char *prev_name; // For constructors/destructors.
157- int prev_name_length; // For constructors/destructors.
158- short nest_level; // For nested names.
159- bool append; // Append flag.
160- bool overflowed; // True if output gets overflowed.
152+ const char *mangled_cur; // Cursor of mangled name.
153+ char *out_cur; // Cursor of output string.
154+ const char *out_begin; // Beginning of output string.
155+ const char *out_end; // End of output string.
156+ const char *prev_name; // For constructors/destructors.
157+ ssize_t prev_name_length; // For constructors/destructors.
158+ short nest_level; // For nested names.
159+ bool append; // Append flag.
160+ bool overflowed; // True if output gets overflowed.
161161} State;
162162
163163// We don't use strlen() in libc since it's not guaranteed to be async
@@ -172,8 +172,8 @@ static size_t StrLen(const char *str) {
172172}
173173
174174// Returns true if "str" has at least "n" characters remaining.
175- static bool AtLeastNumCharsRemaining (const char *str, int n) {
176- for (int i = 0 ; i < n; ++i) {
175+ static bool AtLeastNumCharsRemaining (const char *str, ssize_t n) {
176+ for (ssize_t i = 0 ; i < n; ++i) {
177177 if (str[i] == ' \0 ' ) {
178178 return false ;
179179 }
@@ -269,9 +269,8 @@ static bool ZeroOrMore(ParseFunc parse_func, State *state) {
269269// Append "str" at "out_cur". If there is an overflow, "overflowed"
270270// is set to true for later use. The output string is ensured to
271271// always terminate with '\0' as long as there is no overflow.
272- static void Append (State *state, const char * const str, const int length) {
273- int i;
274- for (i = 0 ; i < length; ++i) {
272+ static void Append (State *state, const char * const str, ssize_t length) {
273+ for (ssize_t i = 0 ; i < length; ++i) {
275274 if (state->out_cur + 1 < state->out_end ) { // +1 for '\0'
276275 *state->out_cur = str[i];
277276 ++state->out_cur ;
@@ -327,7 +326,7 @@ static bool IsFunctionCloneSuffix(const char *str) {
327326// Append "str" with some tweaks, iff "append" state is true.
328327// Returns true so that it can be placed in "if" conditions.
329328static void MaybeAppendWithLength (State *state, const char * const str,
330- const int length) {
329+ ssize_t length) {
331330 if (state->append && length > 0 ) {
332331 // Append a space if the output buffer ends with '<' and "str"
333332 // starts with '<' to avoid <<<.
@@ -347,8 +346,8 @@ static void MaybeAppendWithLength(State *state, const char * const str,
347346// A convenient wrapper arount MaybeAppendWithLength().
348347static bool MaybeAppend (State *state, const char * const str) {
349348 if (state->append ) {
350- int length = StrLen (str);
351- MaybeAppendWithLength (state, str, length);
349+ size_t length = StrLen (str);
350+ MaybeAppendWithLength (state, str, static_cast < ssize_t >( length) );
352351 }
353352 return true ;
354353}
@@ -402,10 +401,10 @@ static void MaybeCancelLastSeparator(State *state) {
402401
403402// Returns true if the identifier of the given length pointed to by
404403// "mangled_cur" is anonymous namespace.
405- static bool IdentifierIsAnonymousNamespace (State *state, int length) {
404+ static bool IdentifierIsAnonymousNamespace (State *state, ssize_t length) {
406405 static const char anon_prefix[] = " _GLOBAL__N_" ;
407- return (length >
408- static_cast < int >( sizeof (anon_prefix)) - 1 && // Should be longer.
406+ return (length > static_cast < ssize_t >( sizeof (anon_prefix)) -
407+ 1 && // Should be longer.
409408 StrPrefix (state->mangled_cur , anon_prefix));
410409}
411410
@@ -423,7 +422,7 @@ static bool ParseLocalSourceName(State *state);
423422static bool ParseNumber (State *state, int *number_out);
424423static bool ParseFloatNumber (State *state);
425424static bool ParseSeqId (State *state);
426- static bool ParseIdentifier (State *state, int length);
425+ static bool ParseIdentifier (State *state, ssize_t length);
427426static bool ParseAbiTags (State *state);
428427static bool ParseAbiTag (State *state);
429428static bool ParseOperatorName (State *state);
@@ -692,7 +691,7 @@ static bool ParseSeqId(State *state) {
692691}
693692
694693// <identifier> ::= <unqualified source code identifier> (of given length)
695- static bool ParseIdentifier (State *state, int length) {
694+ static bool ParseIdentifier (State *state, ssize_t length) {
696695 if (length == -1 ||
697696 !AtLeastNumCharsRemaining (state->mangled_cur , length)) {
698697 return false ;
@@ -892,7 +891,7 @@ static bool ParseCtorDtorName(State *state) {
892891 if (ParseOneCharToken (state, ' C' ) &&
893892 ParseCharClass (state, " 123" )) {
894893 const char * const prev_name = state->prev_name ;
895- const int prev_name_length = state->prev_name_length ;
894+ const ssize_t prev_name_length = state->prev_name_length ;
896895 MaybeAppendWithLength (state, prev_name, prev_name_length);
897896 return true ;
898897 }
@@ -901,7 +900,7 @@ static bool ParseCtorDtorName(State *state) {
901900 if (ParseOneCharToken (state, ' D' ) &&
902901 ParseCharClass (state, " 012" )) {
903902 const char * const prev_name = state->prev_name ;
904- const int prev_name_length = state->prev_name_length ;
903+ const ssize_t prev_name_length = state->prev_name_length ;
905904 MaybeAppend (state, " ~" );
906905 MaybeAppendWithLength (state, prev_name, prev_name_length);
907906 return true ;
0 commit comments