summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmailutils/base/amd.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index 8a7ee9b68..17ef4e456 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -254,18 +254,22 @@ amd_msg_bsearch (struct _amd_data *amd, mu_off_t first, mu_off_t last,
mu_off_t mid;
int rc;
- if (last < first)
- return 1;
-
- mid = (first + last) / 2;
- rc = amd->msg_cmp (amd->msg_array[mid], msg);
- if (rc > 0)
- return amd_msg_bsearch (amd, first, mid-1, msg, pret);
- *pret = mid;
- if (rc < 0)
- return amd_msg_bsearch (amd, mid+1, last, msg, pret);
- /* else */
- return 0;
+ while (first <= last)
+ {
+ mid = (first + last) / 2;
+ rc = amd->msg_cmp (amd->msg_array[mid], msg);
+ if (rc > 0)
+ last = mid - 1;
+ else
+ {
+ *pret = mid;
+ if (rc < 0)
+ first = mid + 1;
+ else
+ return 0;
+ }
+ }
+ return 1;
}
/* Search for message MSG in the message array of AMD.

Return to:

Send suggestions and report system problems to the System administrator.