aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2024-04-11 20:34:17 -0600
committerTom Tromey <tom@tromey.com>2024-04-17 16:10:31 -0600
commitb060213e0c9866469600b31ed570f483b3281c96 (patch)
tree6919cd26603a1f6274095cada3e9556aec764fce /gdb/c-exp.y
parent56f4dea207d690fff70a3ccb6fe10ebe1e4697c0 (diff)
downloadgdb-b060213e0c9866469600b31ed570f483b3281c96.zip
gdb-b060213e0c9866469600b31ed570f483b3281c96.tar.gz
gdb-b060213e0c9866469600b31ed570f483b3281c96.tar.bz2
Remove a copy from c-exp.y:parse_number
parse_number copies its input string, but there is no need to do this. This patch removes the copy. Regression tested on x86-64 Fedora 38. Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y31
1 files changed, 13 insertions, 18 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 459a4cf..663c30f 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1940,46 +1940,41 @@ parse_number (struct parser_state *par_state,
/* We have found a "L" or "U" (or "i") suffix. */
int found_suffix = 0;
- char *p;
-
- p = (char *) alloca (len);
- memcpy (p, buf, len);
-
if (parsed_float)
{
- if (len >= 1 && p[len - 1] == 'i')
+ if (len >= 1 && buf[len - 1] == 'i')
{
imaginary_p = true;
--len;
}
/* Handle suffixes for decimal floating-point: "df", "dd" or "dl". */
- if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
+ if (len >= 2 && buf[len - 2] == 'd' && buf[len - 1] == 'f')
{
putithere->typed_val_float.type
= parse_type (par_state)->builtin_decfloat;
len -= 2;
}
- else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
+ else if (len >= 2 && buf[len - 2] == 'd' && buf[len - 1] == 'd')
{
putithere->typed_val_float.type
= parse_type (par_state)->builtin_decdouble;
len -= 2;
}
- else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
+ else if (len >= 2 && buf[len - 2] == 'd' && buf[len - 1] == 'l')
{
putithere->typed_val_float.type
= parse_type (par_state)->builtin_declong;
len -= 2;
}
/* Handle suffixes: 'f' for float, 'l' for long double. */
- else if (len >= 1 && TOLOWER (p[len - 1]) == 'f')
+ else if (len >= 1 && TOLOWER (buf[len - 1]) == 'f')
{
putithere->typed_val_float.type
= parse_type (par_state)->builtin_float;
len -= 1;
}
- else if (len >= 1 && TOLOWER (p[len - 1]) == 'l')
+ else if (len >= 1 && TOLOWER (buf[len - 1]) == 'l')
{
putithere->typed_val_float.type
= parse_type (par_state)->builtin_long_double;
@@ -1992,7 +1987,7 @@ parse_number (struct parser_state *par_state,
= parse_type (par_state)->builtin_double;
}
- if (!parse_float (p, len,
+ if (!parse_float (buf, len,
putithere->typed_val_float.type,
putithere->typed_val_float.val))
return ERROR;
@@ -2005,14 +2000,14 @@ parse_number (struct parser_state *par_state,
}
/* Handle base-switching prefixes 0x, 0t, 0d, 0 */
- if (p[0] == '0' && len > 1)
- switch (p[1])
+ if (buf[0] == '0' && len > 1)
+ switch (buf[1])
{
case 'x':
case 'X':
if (len >= 3)
{
- p += 2;
+ buf += 2;
base = 16;
len -= 2;
}
@@ -2022,7 +2017,7 @@ parse_number (struct parser_state *par_state,
case 'B':
if (len >= 3)
{
- p += 2;
+ buf += 2;
base = 2;
len -= 2;
}
@@ -2034,7 +2029,7 @@ parse_number (struct parser_state *par_state,
case 'D':
if (len >= 3)
{
- p += 2;
+ buf += 2;
base = 10;
len -= 2;
}
@@ -2047,7 +2042,7 @@ parse_number (struct parser_state *par_state,
while (len-- > 0)
{
- c = *p++;
+ c = *buf++;
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
if (c != 'l' && c != 'u' && c != 'i')