Browse Source

* Fix memory leak in reorder.c.
* Don't crash on symbols at negative locations in constmrg.c.


git-svn-id: file:///var/svn/tigccpp/trunk/tigcc/ld-tigcc@259 9552661e-59e3-4036-b4f2-dbe53926924f

kevinkofler 19 years ago
parent
commit
4635f4967c
2 changed files with 14 additions and 0 deletions
  1. 12 0
      constmrg.c
  2. 2 0
      reorder.c

+ 12 - 0
constmrg.c

@@ -65,6 +65,12 @@ void MergeConstants (PROGRAM *Program)
 			OFFSET Constant1Start = Symbol1->Location, Constant1End, Constant1Length;
 			SECTION *Section2, *NextSection2;
 			NextSymbol1 = FindSymbolAtPos (Section1, Symbol1->Location + 1, TRUE);
+			if (Constant1Start < 0)
+			{
+				Warning (Section1->FileName, "Symbol at negative location -0x%lx",
+				         - (long) Symbol1->Location);
+				continue;
+			}
 			Constant1End = NextSymbol1 ? NextSymbol1->Location : Section1->Size;
 			Constant1Length = Constant1End - Constant1Start;
 			// Loop through all constants in the following sections.
@@ -78,6 +84,12 @@ void MergeConstants (PROGRAM *Program)
 					// Compute the length of the constant.
 					OFFSET Constant2Start = Symbol2->Location, Constant2End, Constant2Length;
 					NextSymbol2 = FindSymbolAtPos (Section2, Symbol2->Location + 1, TRUE);
+					if (Constant2Start < 0)
+					{
+						Warning (Section2->FileName, "Symbol at negative location -0x%lx",
+						         - (long) Symbol2->Location);
+						continue;
+					}
 					Constant2End = NextSymbol2 ? NextSymbol2->Location : Section2->Size;
 					Constant2Length = Constant2End - Constant2Start;
 					// Check if one constant is a prefix of the other.

+ 2 - 0
reorder.c

@@ -464,6 +464,7 @@ static SI1 ReorderSectionsRecurse(PROGRAM *Program, COUNT SectionCount,
 				{
 					Sections[RecursionDepth++] = RemainingSection;
 				}
+				free(TaggedSections);
 				return 1;
   			}
 			// Compute an estimation of the savings for placing each of the sections
@@ -488,6 +489,7 @@ static SI1 ReorderSectionsRecurse(PROGRAM *Program, COUNT SectionCount,
 				{
 					Warning(NULL, "Impossible section arrangement rejected at "
 					              "recursion depth %ld.", (long) RecursionDepth);
+					free(TaggedSections);
 					return 0;
 				}
 				if (CurrentSection->StartupNumber == StartupNumber)