Excerpts from Alan Modra's message of September 4, 2020 3:34 pm:
> So this one is on top of the previously posted patch.
> 
>       * d-demangle.c (string_need): Take a size_t n arg, and use size_t tem.
>       (string_append): Use size_t n.
>       (string_appendn, string_prependn): Take a size_t n arg.
>       (TEMPLATE_LENGTH_UNKNOWN): Define as -1UL.
>       * d-demangle.c (dlang_number): Make "ret" an unsigned long*.
>       Only succeed for result of [0,4294967295UL].
>       (dlang_decode_backref): Only succeed for result [1,MAX_LONG].
>       (dlang_backref): Remove now unnecessary range check.
>       (dlang_symbol_name_p): Likewise.
>       (dlang_lname, dlang_parse_template): Take an unsigned long len
>       arg.
>       (dlang_symbol_backref, dlang_identifier, dlang_parse_integer),
>       (dlang_parse_integer, dlang_parse_string),
>       (dlang_parse_arrayliteral, dlang_parse_assocarray),
>       (dlang_parse_structlit, dlang_parse_tuple),
>       (dlang_template_symbol_param, dlang_template_args): Use
>       unsigned long variables.
>       * testsuite/d-demangle-expected: Add new tests.
> 
> diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
> index 59e6ae007a..152f620abf 100644
> --- a/libiberty/d-demangle.c
> +++ b/libiberty/d-demangle.c
> @@ -62,9 +62,9 @@ typedef struct string               /* Beware: these aren't 
> required to be */
>  } string;
>  
>  static void
> -string_need (string *s, int n)
> +string_need (string *s, size_t n)
>  {
> -  int tem;
> +  size_t tem;
>  
>    if (s->b == NULL)
>      {
> @@ -75,7 +75,7 @@ string_need (string *s, int n)
>        s->p = s->b = XNEWVEC (char, n);
>        s->e = s->b + n;
>      }
> -  else if (s->e - s->p < n)
> +  else if ((size_t) (s->e - s->p) < n)
>      {
>        tem = s->p - s->b;
>        n += tem;
> @@ -124,14 +124,14 @@ string_setlength (string *s, int n)
>  static void
>  string_append (string *p, const char *s)
>  {
> -  int n = strlen (s);
> +  size_t n = strlen (s);
>    string_need (p, n);
>    memcpy (p->p, s, n);
>    p->p += n;
>  }
>  
>  static void
> -string_appendn (string *p, const char *s, int n)
> +string_appendn (string *p, const char *s, size_t n)
>  {
>    if (n != 0)
>      {
> @@ -142,7 +142,7 @@ string_appendn (string *p, const char *s, int n)
>  }
>  
>  static void
> -string_prependn (string *p, const char *s, int n)
> +string_prependn (string *p, const char *s, size_t n)
>  {
>    char *q;
>  
> @@ -177,7 +177,7 @@ struct dlang_info
>  };
>  
>  /* Pass as the LEN to dlang_parse_template if symbol length is not known.  */
> -enum { TEMPLATE_LENGTH_UNKNOWN = -1 };
> +#define TEMPLATE_LENGTH_UNKNOWN (-1UL)
>  
>  /* Prototypes for forward referenced functions */
>  static const char *dlang_function_type (string *, const char *,
> @@ -200,15 +200,16 @@ static const char *dlang_parse_tuple (string *, const 
> char *,
>                                     struct dlang_info *);
>  
>  static const char *dlang_parse_template (string *, const char *,
> -                                      struct dlang_info *, long);
> +                                      struct dlang_info *, unsigned long);
>  
> -static const char *dlang_lname (string *, const char *, long);
> +static const char *dlang_lname (string *, const char *, unsigned long);
>  
>  
>  /* Extract the number from MANGLED, and assign the result to RET.
> -   Return the remaining string on success or NULL on failure.  */
> +   Return the remaining string on success or NULL on failure.
> +   A result larger than 4294967295UL is considered a failure.  */

If we're already using limits.h, I guess it should be fine to also add

#define UINT_MAX ((unsigned) ~0U)

I'll leave it to your judgement on that though.

Other than that, OK from me.

Iain.

Reply via email to