public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Andreas Schwab <schwab@suse.de>
Cc: Hans-Peter Nilsson <hp@bitrange.com>, binutils@sourceware.org
Subject: Re: [PATCH] Make the compiler do the math 2.
Date: Tue, 26 Sep 2006 08:49:00 -0000	[thread overview]
Message-ID: <4518E163.7040402@redhat.com> (raw)
In-Reply-To: <jelko7bs2d.fsf@sykes.suse.de>

Hi Andreas,

> How about just using strcpy?  

strcpy also copies the NUL byte at the end of the string, which may not 
be desired in all circumstances, (although in this particular case it is 
OK).

> Also, the surrounding code has too many
> occurrences of magic numbers that should be replaced. 

A very good idea.

> Like this perhaps:

> --- bfd/elflink.c.~1.230.~	2006-09-18 10:58:08.000000000 +0200
> +++ bfd/elflink.c	2006-09-25 22:34:35.000000000 +0200
> @@ -9699,13 +9699,16 @@ bfd_elf_gc_sections (bfd *abfd, struct b
>  		unsigned long len;
>  		char *fn_name;
>  		asection *fn_text;
> +		int o_name_prefix_len = strlen (".gcc_except_table.");
> +		int fn_name_prefix_len = strlen (".text.");
>  
> -		len = strlen (o->name + 18) + 1;
> -		fn_name = bfd_malloc (len + 6);
> +		len = strlen (o->name + o_name_prefix_len) + 1;
> +		fn_name = bfd_malloc (len + fn_name_prefix_len);
>  		if (fn_name == NULL)
>  		  return FALSE;
> -		memcpy (fn_name, STRING_COMMA_LEN (".text."));
> -		memcpy (fn_name + 6, o->name + 18, len);
> +		strcpy (fn_name, ".text.");
> +		memcpy (fn_name + fn_name_prefix_len,
> +			o->name + o_name_prefix_len, len);
>  		fn_text = bfd_get_section_by_name (sub, fn_name);
>  		free (fn_name);
>  		if (fn_text == NULL || !fn_text->gc_mark)

I like this, although for my money I think that we would be better off 
replacing the multiple occurrences of the same constant string with a 
#define, just to make it clear that we are intentionally dealing with 
the same piece of text.  eg:

   #define DOT_TEXT_DOT ".text."
   ...
   int fn_name_prefix_len = sizeof (DOT_TEXT_DOT) - 1;
   ...
   strcpy (fn_name, DOT_TEXT_DOT);

Cheers
   Nick

  reply	other threads:[~2006-09-26  8:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-11 21:03 Pedro Alves
2006-09-12 11:27 ` Pedro Alves
2006-09-16 18:16   ` Nick Clifton
2006-09-17  3:39     ` Regression with strn-stuff (was: Re: [PATCH] Make the compiler do the math 2.) Hans-Peter Nilsson
2006-09-17 14:41       ` Regression with strn-stuff Nick Clifton
2006-09-17 18:58         ` Pedro Alves
2006-09-17 19:17           ` Hans-Peter Nilsson
2006-09-17 22:20             ` [PATCH]: " Pedro Alves
2006-09-19 10:37               ` Pedro Alves
2006-09-25 16:14                 ` Nick Clifton
2006-09-25 16:19                 ` Andreas Schwab
2006-09-17 19:08         ` Hans-Peter Nilsson
2006-09-25 16:09           ` Nick Clifton
2006-09-25 14:01     ` [PATCH] Make the compiler do the math 2 Andreas Schwab
2006-09-25 17:14       ` Nick Clifton
2006-09-25 19:37         ` Andreas Schwab
2006-09-25 20:38       ` Hans-Peter Nilsson
2006-09-25 22:23         ` Andreas Schwab
2006-09-26  8:49           ` Nick Clifton [this message]
2006-09-26 10:17           ` Nick Clifton
2006-09-26 10:30             ` Andreas Schwab
2006-09-26 12:38             ` Pedro Alves
2006-09-25 23:53         ` Pedro Alves
2006-09-28 13:25           ` Nick Clifton

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=4518E163.7040402@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=hp@bitrange.com \
    --cc=schwab@suse.de \
    /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).