Bug 18316: Safer way to adjust frame sizes - prevent possible UMR and segfaults r=harishd

This commit is contained in:
pollmann@netscape.com
2000-01-07 05:49:20 +00:00
parent c26c8c254c
commit 1d773de37d
4 changed files with 20 additions and 16 deletions

View File

@@ -288,6 +288,7 @@ nsHTMLFramesetFrame::Init(nsIPresContext* aPresContext,
void nsHTMLFramesetFrame::Scale(nscoord aDesired, void nsHTMLFramesetFrame::Scale(nscoord aDesired,
PRInt32 aNumIndicies, PRInt32 aNumIndicies,
PRInt32* aIndicies, PRInt32* aIndicies,
PRInt32 aNumItems,
PRInt32* aItems) PRInt32* aItems)
{ {
PRInt32 actual = 0; PRInt32 actual = 0;
@@ -309,12 +310,12 @@ void nsHTMLFramesetFrame::Scale(nscoord aDesired,
if ((aNumIndicies > 0) && (aDesired != actual)) { if ((aNumIndicies > 0) && (aDesired != actual)) {
PRInt32 unit = (aDesired > actual) ? 1 : -1; PRInt32 unit = (aDesired > actual) ? 1 : -1;
i = 0; for (i=0; (i < aNumIndicies) && (aDesired != actual); i++) {
while (aDesired != actual) {
j = aIndicies[i]; j = aIndicies[i];
aItems[j] += unit; if (j < aNumItems) {
actual += unit; aItems[j] += unit;
i++; actual += unit;
}
} }
} }
} }
@@ -369,7 +370,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the fixed sizes if they total too much (or too little and there aren't any percent or relative) // scale the fixed sizes if they total too much (or too little and there aren't any percent or relative)
if ((fixedTotal > aSize) || ((fixedTotal < aSize) && (0 == numPercent) && (0 == numRelative))) { if ((fixedTotal > aSize) || ((fixedTotal < aSize) && (0 == numPercent) && (0 == numRelative))) {
Scale(aSize, numFixed, fixed, aValues); Scale(aSize, numFixed, fixed, aNumSpecs, aValues);
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;
return; return;
} }
@@ -385,7 +386,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the percent sizes if they total too much (or too little and there aren't any relative) // scale the percent sizes if they total too much (or too little and there aren't any relative)
if ((percentTotal > percentMax) || ((percentTotal < percentMax) && (0 == numRelative))) { if ((percentTotal > percentMax) || ((percentTotal < percentMax) && (0 == numRelative))) {
Scale(percentMax, numPercent, percent, aValues); Scale(percentMax, numPercent, percent, aNumSpecs, aValues);
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;
return; return;
} }
@@ -401,7 +402,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the relative sizes if they take up too much or too little // scale the relative sizes if they take up too much or too little
if (relativeTotal != relativeMax) { if (relativeTotal != relativeMax) {
Scale(relativeMax, numRelative, relative, aValues); Scale(relativeMax, numRelative, relative, aNumSpecs, aValues);
} }
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;

View File

@@ -166,6 +166,7 @@ protected:
void Scale(nscoord aDesired, void Scale(nscoord aDesired,
PRInt32 aNumIndicies, PRInt32 aNumIndicies,
PRInt32* aIndicies, PRInt32* aIndicies,
PRInt32 aNumItems,
PRInt32* aItems); PRInt32* aItems);
void CalculateRowCol(nsIPresContext* aPresContext, void CalculateRowCol(nsIPresContext* aPresContext,

View File

@@ -288,6 +288,7 @@ nsHTMLFramesetFrame::Init(nsIPresContext* aPresContext,
void nsHTMLFramesetFrame::Scale(nscoord aDesired, void nsHTMLFramesetFrame::Scale(nscoord aDesired,
PRInt32 aNumIndicies, PRInt32 aNumIndicies,
PRInt32* aIndicies, PRInt32* aIndicies,
PRInt32 aNumItems,
PRInt32* aItems) PRInt32* aItems)
{ {
PRInt32 actual = 0; PRInt32 actual = 0;
@@ -309,12 +310,12 @@ void nsHTMLFramesetFrame::Scale(nscoord aDesired,
if ((aNumIndicies > 0) && (aDesired != actual)) { if ((aNumIndicies > 0) && (aDesired != actual)) {
PRInt32 unit = (aDesired > actual) ? 1 : -1; PRInt32 unit = (aDesired > actual) ? 1 : -1;
i = 0; for (i=0; (i < aNumIndicies) && (aDesired != actual); i++) {
while (aDesired != actual) {
j = aIndicies[i]; j = aIndicies[i];
aItems[j] += unit; if (j < aNumItems) {
actual += unit; aItems[j] += unit;
i++; actual += unit;
}
} }
} }
} }
@@ -369,7 +370,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the fixed sizes if they total too much (or too little and there aren't any percent or relative) // scale the fixed sizes if they total too much (or too little and there aren't any percent or relative)
if ((fixedTotal > aSize) || ((fixedTotal < aSize) && (0 == numPercent) && (0 == numRelative))) { if ((fixedTotal > aSize) || ((fixedTotal < aSize) && (0 == numPercent) && (0 == numRelative))) {
Scale(aSize, numFixed, fixed, aValues); Scale(aSize, numFixed, fixed, aNumSpecs, aValues);
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;
return; return;
} }
@@ -385,7 +386,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the percent sizes if they total too much (or too little and there aren't any relative) // scale the percent sizes if they total too much (or too little and there aren't any relative)
if ((percentTotal > percentMax) || ((percentTotal < percentMax) && (0 == numRelative))) { if ((percentTotal > percentMax) || ((percentTotal < percentMax) && (0 == numRelative))) {
Scale(percentMax, numPercent, percent, aValues); Scale(percentMax, numPercent, percent, aNumSpecs, aValues);
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;
return; return;
} }
@@ -401,7 +402,7 @@ void nsHTMLFramesetFrame::CalculateRowCol(nsIPresContext* aPresContext,
// scale the relative sizes if they take up too much or too little // scale the relative sizes if they take up too much or too little
if (relativeTotal != relativeMax) { if (relativeTotal != relativeMax) {
Scale(relativeMax, numRelative, relative, aValues); Scale(relativeMax, numRelative, relative, aNumSpecs, aValues);
} }
delete [] fixed; delete [] percent; delete [] relative; delete [] fixed; delete [] percent; delete [] relative;

View File

@@ -166,6 +166,7 @@ protected:
void Scale(nscoord aDesired, void Scale(nscoord aDesired,
PRInt32 aNumIndicies, PRInt32 aNumIndicies,
PRInt32* aIndicies, PRInt32* aIndicies,
PRInt32 aNumItems,
PRInt32* aItems); PRInt32* aItems);
void CalculateRowCol(nsIPresContext* aPresContext, void CalculateRowCol(nsIPresContext* aPresContext,