Commit 4ed3a4d4 by Thomas Koenig

re PR libfortran/54736 (GFORTRAN_CONVERT_UNIT causes malloc error on several platforms)

2012-10-06  Thomas König  <tkoenig@gcc.gnu.org>

	PR libfortran/54736
	* runtime/environ.c (search_unit):  Correct logic
	for binary search.
	(mark_single):  Fix index errors.

From-SVN: r192158
parent e9355cc3
2012-10-06 Thomas König <tkoenig@gcc.gnu.org>
PR libfortran/54736
* runtime/environ.c (search_unit): Correct logic
for binary search.
(mark_single): Fix index errors.
2012-09-29 Thomas König <tkoenig@gcc.gnu.org> 2012-09-29 Thomas König <tkoenig@gcc.gnu.org>
PR fortran/52724 PR fortran/52724
......
...@@ -459,20 +459,34 @@ search_unit (int unit, int *ip) ...@@ -459,20 +459,34 @@ search_unit (int unit, int *ip)
{ {
int low, high, mid; int low, high, mid;
low = -1; if (n_elist == 0)
high = n_elist;
while (high - low > 1)
{ {
mid = (low + high) / 2; *ip = 0;
if (unit <= elist[mid].unit) return 0;
high = mid;
else
low = mid;
} }
*ip = high;
if (elist[high].unit == unit) low = 0;
high = n_elist - 1;
do
{
mid = (low + high) / 2;
if (unit == elist[mid].unit)
{
*ip = mid;
return 1; return 1;
}
else if (unit > elist[mid].unit)
low = mid + 1;
else else
high = mid - 1;
} while (low <= high);
if (unit > elist[mid].unit)
*ip = mid + 1;
else
*ip = mid;
return 0; return 0;
} }
...@@ -588,11 +602,11 @@ mark_single (int unit) ...@@ -588,11 +602,11 @@ mark_single (int unit)
} }
if (search_unit (unit, &i)) if (search_unit (unit, &i))
{ {
elist[unit].conv = endian; elist[i].conv = endian;
} }
else else
{ {
for (j=n_elist; j>=i; j--) for (j=n_elist-1; j>=i; j--)
elist[j+1] = elist[j]; elist[j+1] = elist[j];
n_elist += 1; n_elist += 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment