This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] memcmp() error in gas/dwarf2dbg.c


Jakub Jelinek wrote:
On Fri, Feb 13, 2004 at 12:21:30PM +0100, Andreas Jaeger wrote:

--- binutils-2.14.90.0.8/gas/dwarf2dbg..c.orig	2004-02-13 11:55:05.470239719 +0100
+++ binutils-2.14.90.0.8/gas/dwarf2dbg.c	2004-02-13 11:57:23.679576129 +0100

Note this patch applies also to current CVS, Hannes noticed it with a segmentation fault of gas due to accessing beyond the allocated memory.


[ Patch deleted ]


I very much doubt it has been tested at all.
Previously it has been doing if (...) break; in the for cycle, now
it does just tmp_len = in the for cycle and if (...) break; afterwards.
Also, calling strlen twice is a waste, relying on compiler to optimize
it out is wrong.  And doing even one strlen in the cycle is too expensive.
I believe using
strncmp (filename, dirs[dir], dir_len) == 0 && dirs[dir][dir_len] == '\0'
would be much better.


Like this?


Cheers,

Hannes
--
Dr. Hannes Reinecke			hare@suse.de
SuSE Linux AG				S390 & zSeries
Maxfeldstraße 5				+49 911 74053 688
90409 Nürnberg				http://www.suse.de
--- binutils-2.14.90.0.8/gas/dwarf2dbg.c.orig	2004-02-13 12:44:42.306841116 +0100
+++ binutils-2.14.90.0.8/gas/dwarf2dbg.c	2004-02-13 12:45:04.418980440 +0100
@@ -372,7 +372,7 @@
     {
       --dir_len;
       for (dir = 1; dir < dirs_in_use; ++dir)
-	if (memcmp (filename, dirs[dir], dir_len) == 0
+	if (strncmp (filename, dirs[dir], dir_len) == 0
 	    && dirs[dir][dir_len] == '\0')
 	  break;
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]