libiberty patch committed: Minor optimization (PR 54800)

Submitted by Ian Taylor on Jan. 4, 2013, 7 p.m.

Details

Message ID mcrfw2gg4ed.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Jan. 4, 2013, 7 p.m.
PR 54800 points out a minor optimization uncovered by cppcheck.  This
optimization is not important, but we might as well fix it in case
cppcheck comes up with something useful.

Tested by Iain Sandoe (thanks!).  Committed to mainline.

Ian


2013-01-04  Ian Lance Taylor  <iant@google.com>

	PR other/54800
	* simple-object-mach-o.c (simple_object_mach_o_segment): Don't
	bother to zero out a buffer we are about to set anyhow.

Patch hide | download patch | download mbox

Index: simple-object-mach-o.c
===================================================================
--- simple-object-mach-o.c	(revision 194911)
+++ simple-object-mach-o.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* simple-object-mach-o.c -- routines to manipulate Mach-O object files.
-   Copyright 2010, 2011 Free Software Foundation, Inc.
+   Copyright 2010, 2011, 2013 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Google.
 
 This program is free software; you can redistribute it and/or modify it
@@ -701,12 +701,13 @@  simple_object_mach_o_segment (simple_obj
 	   /* Otherwise, make a name like __segment,__section as per the
 	      convention in mach-o asm.  */
 	  name = &namebuf[0];
-	  memset (namebuf, 0, MACH_O_NAME_LEN * 2 + 2);
 	  memcpy (namebuf, (char *) sechdr + segname_offset, MACH_O_NAME_LEN);
+	  namebuf[MACH_O_NAME_LEN] = '\0';
 	  l = strlen (namebuf);
 	  namebuf[l] = ',';
 	  memcpy (namebuf + l + 1, (char *) sechdr + sectname_offset,
 		  MACH_O_NAME_LEN);
+	  namebuf[l + 1 + MACH_O_NAME_LEN] = '\0';
 	}
 
       simple_object_mach_o_section_info (omr->is_big_endian, is_32, sechdr,