[cmake-commits] king committed cmELF.cxx 1.4 1.5 cmELF.h 1.2 1.3

cmake-commits at cmake.org cmake-commits at cmake.org
Sat Mar 1 12:50:44 EST 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv22409/Source

Modified Files:
	cmELF.cxx cmELF.h 
Log Message:
ENH: Add Size member to cmELF::StringEntry to return the amount of space in the string entry.


Index: cmELF.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmELF.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cmELF.h	29 Feb 2008 16:12:59 -0000	1.2
+++ cmELF.h	1 Mar 2008 17:50:42 -0000	1.3
@@ -62,6 +62,10 @@
 
     // The position in the file at which the string appears.
     unsigned long Position;
+
+    // The size of the string table entry.  This includes the space
+    // allocated for one or more null terminators.
+    unsigned long Size;
   };
 
   /** Get the type of the file opened.  */

Index: cmELF.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmELF.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cmELF.cxx	29 Feb 2008 16:12:59 -0000	1.4
+++ cmELF.cxx	1 Mar 2008 17:50:42 -0000	1.5
@@ -488,6 +488,7 @@
   // Create an entry for this tag.  Assume it is missing until found.
   StringEntry& se = this->DynamicSectionStrings[tag];
   se.Position = 0;
+  se.Size = 0;
 
   // Try reading the dynamic section.
   if(!this->LoadDynamicSection())
@@ -512,14 +513,39 @@
     ELF_Dyn& dyn = *di;
     if(dyn.d_tag == tag)
       {
+      // We found the tag requested.
+      // Make sure the position given is within the string section.
+      if(dyn.d_un.d_val >= strtab.sh_size)
+        {
+        this->SetErrorMessage("Section DYNAMIC references string beyond "
+                              "the end of its string section.");
+        return 0;
+        }
+
       // Seek to the position reported by the entry.
-      this->Stream.seekg(strtab.sh_offset + dyn.d_un.d_val);
+      unsigned long first = static_cast<unsigned long>(dyn.d_un.d_val);
+      unsigned long last = first;
+      unsigned long end = static_cast<unsigned long>(strtab.sh_size);
+      this->Stream.seekg(strtab.sh_offset + first);
 
-      // Read the string.
+      // Read the string.  It may be followed by more than one NULL
+      // terminator.  Count the total size of the region allocated to
+      // the string.  This assumes that the next string in the table
+      // is non-empty, but the "chrpath" tool makes the same
+      // assumption.
+      bool terminated = false;
       char c;
-      while(this->Stream.get(c) && c != 0)
+      while(last != end && this->Stream.get(c) && !(terminated && c))
         {
-        se.Value += c;
+        ++last;
+        if(c)
+          {
+          se.Value += c;
+          }
+        else
+          {
+          terminated = true;
+          }
         }
 
       // Make sure the whole value was read.
@@ -531,8 +557,8 @@
         }
 
       // The value has been read successfully.  Report it.
-      se.Position =
-        static_cast<unsigned long>(strtab.sh_offset + dyn.d_un.d_val);
+      se.Position = static_cast<unsigned long>(strtab.sh_offset + first);
+      se.Size = last - first;
       return &se;
       }
     }



More information about the Cmake-commits mailing list