]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Remove extra memory allocation of strings.
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 9 Nov 2018 13:01:19 +0000 (13:01 +0000)
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 9 Nov 2018 13:01:19 +0000 (13:01 +0000)
2018-11-09  Martin Liska  <mliska@suse.cz>

* config/aarch64/aarch64.c (aarch64_parse_arch): Do not copy
string to a stack buffer.
(aarch64_parse_cpu): Likewise.
(aarch64_parse_tune): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265966 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/aarch64/aarch64.c

index 693ac972e5ffe3e1a81c5af18fa7dec4525b51c6..23accf398da0fbb297deea54a02e0219a8c534ab 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-09  Martin Liska  <mliska@suse.cz>
+
+       * config/aarch64/aarch64.c (aarch64_parse_arch): Do not copy
+       string to a stack buffer.
+       (aarch64_parse_cpu): Likewise.
+       (aarch64_parse_tune): Likewise.
+
 2018-11-09  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/87953
index c82c7b6aa2c3f346a551afdd368eff8bd7544d2c..815f82457a790d2168a6e4c09444fcc59ea5d081 100644 (file)
@@ -10553,19 +10553,16 @@ static enum aarch64_parse_opt_result
 aarch64_parse_arch (const char *to_parse, const struct processor **res,
                    unsigned long *isa_flags, std::string *invalid_extension)
 {
-  char *ext;
+  const char *ext;
   const struct processor *arch;
-  char *str = (char *) alloca (strlen (to_parse) + 1);
   size_t len;
 
-  strcpy (str, to_parse);
-
-  ext = strchr (str, '+');
+  ext = strchr (to_parse, '+');
 
   if (ext != NULL)
-    len = ext - str;
+    len = ext - to_parse;
   else
-    len = strlen (str);
+    len = strlen (to_parse);
 
   if (len == 0)
     return AARCH64_PARSE_MISSING_ARG;
@@ -10574,7 +10571,8 @@ aarch64_parse_arch (const char *to_parse, const struct processor **res,
   /* Loop through the list of supported ARCHes to find a match.  */
   for (arch = all_architectures; arch->name != NULL; arch++)
     {
-      if (strlen (arch->name) == len && strncmp (arch->name, str, len) == 0)
+      if (strlen (arch->name) == len
+         && strncmp (arch->name, to_parse, len) == 0)
        {
          unsigned long isa_temp = arch->flags;
 
@@ -10610,19 +10608,16 @@ static enum aarch64_parse_opt_result
 aarch64_parse_cpu (const char *to_parse, const struct processor **res,
                   unsigned long *isa_flags, std::string *invalid_extension)
 {
-  char *ext;
+  const char *ext;
   const struct processor *cpu;
-  char *str = (char *) alloca (strlen (to_parse) + 1);
   size_t len;
 
-  strcpy (str, to_parse);
-
-  ext = strchr (str, '+');
+  ext = strchr (to_parse, '+');
 
   if (ext != NULL)
-    len = ext - str;
+    len = ext - to_parse;
   else
-    len = strlen (str);
+    len = strlen (to_parse);
 
   if (len == 0)
     return AARCH64_PARSE_MISSING_ARG;
@@ -10631,7 +10626,7 @@ aarch64_parse_cpu (const char *to_parse, const struct processor **res,
   /* Loop through the list of supported CPUs to find a match.  */
   for (cpu = all_cores; cpu->name != NULL; cpu++)
     {
-      if (strlen (cpu->name) == len && strncmp (cpu->name, str, len) == 0)
+      if (strlen (cpu->name) == len && strncmp (cpu->name, to_parse, len) == 0)
        {
          unsigned long isa_temp = cpu->flags;
 
@@ -10665,14 +10660,11 @@ static enum aarch64_parse_opt_result
 aarch64_parse_tune (const char *to_parse, const struct processor **res)
 {
   const struct processor *cpu;
-  char *str = (char *) alloca (strlen (to_parse) + 1);
-
-  strcpy (str, to_parse);
 
   /* Loop through the list of supported CPUs to find a match.  */
   for (cpu = all_cores; cpu->name != NULL; cpu++)
     {
-      if (strcmp (cpu->name, str) == 0)
+      if (strcmp (cpu->name, to_parse) == 0)
        {
          *res = cpu;
          return AARCH64_PARSE_OK;