This is the mail archive of the binutils@sourceware.org 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]

gold patch: Add casts to avoid warning


I had to add a couple of casts to avoid a warning about comparing
signed and unsigned values with g++ 4.2.2.  Figuring out the right
casts was a little tricky since this is a comparison between off_t and
size_t, overflow is definitely possible, and it's hard to know which
of off_t and size_t is larger for any given compiler/OS.  I punted and
cast both values to unsigned long long.

Ian


2008-09-16  Ian Lance Taylor  <iant@google.com>

	* fileread.cc (make_view): Add casts to avoid warning.


Index: fileread.cc
===================================================================
RCS file: /cvs/src/src/gold/fileread.cc,v
retrieving revision 1.44
diff -u -p -u -r1.44 fileread.cc
--- fileread.cc	10 Sep 2008 17:56:02 -0000	1.44
+++ fileread.cc	16 Sep 2008 17:16:50 -0000
@@ -356,7 +356,9 @@ File_read::make_view(off_t start, sectio
   gold_assert(size > 0);
 
   // Check that start and end of the view are within the file.
-  if (start > this->size_ || size > this->size_ - start)
+  if (start > this->size_
+      || (static_cast<unsigned long long>(size)
+          > static_cast<unsigned long long>(this->size_ - start)))
     gold_fatal(_("%s: attempt to map %lld bytes at offset %lld exceeds "
                  "size of file; the file may be corrupt"),
 		   this->filename().c_str(),

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