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
This commit is contained in:
Thomas Koenig 2012-10-06 13:04:35 +00:00
parent e9355cc32e
commit 4ed3a4d41b
2 changed files with 35 additions and 14 deletions

View File

@ -1,3 +1,10 @@
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

View File

@ -459,21 +459,35 @@ 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) *ip = 0;
return 0;
}
low = 0;
high = n_elist - 1;
do
{ {
mid = (low + high) / 2; mid = (low + high) / 2;
if (unit <= elist[mid].unit) if (unit == elist[mid].unit)
high = mid; {
*ip = mid;
return 1;
}
else if (unit > elist[mid].unit)
low = mid + 1;
else else
low = mid; high = mid - 1;
} } while (low <= high);
*ip = high;
if (elist[high].unit == unit) if (unit > elist[mid].unit)
return 1; *ip = mid + 1;
else else
return 0; *ip = mid;
return 0;
} }
/* This matches a keyword. If it is found, return the token supplied, /* This matches a keyword. If it is found, return the token supplied,
@ -588,13 +602,13 @@ 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;
elist[i].unit = unit; elist[i].unit = unit;
elist[i].conv = endian; elist[i].conv = endian;