public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@physics.uc.edu>
To: Andrew Pinski <pinskia@physics.uc.edu>
Cc: gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org, apinski@apple.com
Subject: Re: [PATCH] Re: strcat and config/darwin.c
Date: Mon, 03 Feb 2003 06:32:00 -0000	[thread overview]
Message-ID: <33F50DFA-3741-11D7-84EB-000393A6D2F2@physics.uc.edu> (raw)
In-Reply-To: <8BF8B765-3700-11D7-84EB-000393A6D2F2@physics.uc.edu>

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

I messed up the patch, in machopic_classify_ident, I forgot to add one 
to the length to copy the null character.


Here is an updated patch:

[-- Attachment #2: darwin.str.diff --]
[-- Type: application/octet-stream, Size: 2563 bytes --]

--- ../../../../gcc-clean/src/gcc/config/darwin.c	Sat Jan 25 15:19:38 2003
+++ ./darwin.c	Sun Feb  2 22:19:53 2003
@@ -124,8 +124,9 @@ machopic_classify_ident (ident)
   else if (name[1] == 'd' || name[1] == 't')
     {
       char *new_name;
-      new_name = (char *)alloca (strlen (name) + 1);
-      strcpy (new_name, name);
+      int name_len = strlen (name);
+      new_name = (char *)alloca (name_len + 1);
+      memcpy (new_name, name, name_len + 1);
       new_name[1] = (name[1] == 'd') ? 'D' : 'T';
       if (maybe_get_identifier (new_name) != NULL)
 	return  (name[1] == 'd') ? MACHOPIC_DEFINED_DATA
@@ -295,19 +296,24 @@ machopic_non_lazy_ptr_name (name)
   {
     char *buffer;
     tree ptr_name;
+    int len_name = strlen (name);
 
-    buffer = alloca (strlen (name) + 20);
+    buffer = alloca ( len_name + 20);
 
-    strcpy (buffer, "&L");
+    memcpy (buffer, "&L", 2);
     if (name[0] == '*')
-      strcat (buffer, name+1);
+      {
+        memcpy (buffer + 2, name + 1, len_name);
+        len_name -= 1;
+      }
     else
       {
-	strcat (buffer, "_");
-	strcat (buffer, name);
+	memcpy (buffer + 2, "_", 1);
+	memcpy (buffer + 3, name, len_name + 1);
+        len_name += 1;
       }
       
-    strcat (buffer, "$non_lazy_ptr");
+    memcpy (buffer + 2 + len_name, "$non_lazy_ptr", strlen ("$non_lazy_ptr") + 1);
     ptr_name = get_identifier (buffer);
 
     machopic_non_lazy_pointers 
@@ -354,27 +360,37 @@ machopic_stub_name (name)
     char *buffer;
     tree ptr_name;
     int needs_quotes = name_needs_quotes (name);
+    int len=0;
+    int name_len = strlen (name);
 
-    buffer = alloca (strlen (name) + 20);
+    buffer = alloca (name_len + 20);
 
     if (needs_quotes)
-      strcpy (buffer, "&\"L");
+      {
+        len = 3;
+        memcpy (buffer, "&\"L", len);
+      }
     else
-      strcpy (buffer, "&L");
+      {
+        len = 2;
+        memcpy (buffer, "&L", len);
+      }
     if (name[0] == '*')
       {
-	strcat (buffer, name+1);
+        len += name_len-1;
+	memcpy (buffer+len, name+1, name_len);
       }
     else
       {
-	strcat (buffer, "_");
-	strcat (buffer, name);
+	memcpy (buffer + len, "_", 1);
+	memcpy (buffer + len + 1, name, name_len);
+        len += name_len+1;
       }
 
     if (needs_quotes)
-      strcat (buffer, "$stub\"");
+      memcpy (buffer + len, "$stub\"", 7);
     else
-      strcat (buffer, "$stub");
+      memcpy (buffer + len, "$stub", 6);
     ptr_name = get_identifier (buffer);
 
     machopic_stubs = tree_cons (ptr_name, ident, machopic_stubs);

[-- Attachment #3: Type: text/plain, Size: 575 bytes --]




Thanks,
Andrew Pinski
apinski@apple.com
pinskia@physics.uc.edu


On Sunday, Feb 2, 2003, at 14:49 US/Pacific, Andrew Pinski wrote:

> Here is an updated with the suggestion from Richard Henderson by it 
> using memcpy instead of strcpy:
>
> 2003-02-02  Andrew Pinski  <pinskia@physics.uc.edu>
>
> 	* config/darwin.c: (machopic_non_lazy_ptr_name): Change strcat to 
> memcpy with length added.
> 	(machopic_stub_name): Likewise. (machopic_classify_ident): Change 
> strcpy to memcpy.
> <temp.diff>
>
> Thanks,
> Andrew Pinski
> apinski@apple.com
> pinskia@physics.uc.edu
>

  reply	other threads:[~2003-02-03  6:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-26 17:02 Andrew Pinski
2003-01-28 11:02 ` Richard Henderson
2003-02-02 22:49 ` [PATCH] " Andrew Pinski
2003-02-03  6:32   ` Andrew Pinski [this message]
2003-10-05  1:12     ` Andrew Pinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33F50DFA-3741-11D7-84EB-000393A6D2F2@physics.uc.edu \
    --to=pinskia@physics.uc.edu \
    --cc=apinski@apple.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).