summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-06 13:04:35 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-06 13:04:35 +0000
commit0f328cd66581eb00730cce6ca1cc93ecd341a3ad (patch)
tree6ef50bac9c6995525a6e109ca1f1b71824cf4a6e /libgfortran
parent697e174506f3c1b17e6c34332821f790a0d07056 (diff)
downloadgcc-0f328cd66581eb00730cce6ca1cc93ecd341a3ad.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192158 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog7
-rw-r--r--libgfortran/runtime/environ.c42
2 files changed, 35 insertions, 14 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index feeb10a4146..de915f8a78e 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -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>
PR fortran/52724
diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c
index bcb91f44613..1f73397703d 100644
--- a/libgfortran/runtime/environ.c
+++ b/libgfortran/runtime/environ.c
@@ -459,21 +459,35 @@ search_unit (int unit, int *ip)
{
int low, high, mid;
- low = -1;
- high = n_elist;
- while (high - low > 1)
+ if (n_elist == 0)
+ {
+ *ip = 0;
+ return 0;
+ }
+
+ low = 0;
+ high = n_elist - 1;
+
+ do
{
mid = (low + high) / 2;
- if (unit <= elist[mid].unit)
- high = mid;
+ if (unit == elist[mid].unit)
+ {
+ *ip = mid;
+ return 1;
+ }
+ else if (unit > elist[mid].unit)
+ low = mid + 1;
else
- low = mid;
- }
- *ip = high;
- if (elist[high].unit == unit)
- return 1;
+ high = mid - 1;
+ } while (low <= high);
+
+ if (unit > elist[mid].unit)
+ *ip = mid + 1;
else
- return 0;
+ *ip = mid;
+
+ return 0;
}
/* 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))
{
- elist[unit].conv = endian;
+ elist[i].conv = endian;
}
else
{
- for (j=n_elist; j>=i; j--)
+ for (j=n_elist-1; j>=i; j--)
elist[j+1] = elist[j];
-
+
n_elist += 1;
elist[i].unit = unit;
elist[i].conv = endian;