diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 31 | ||||
-rw-r--r-- | src/interfaces/ecpg/pgtypeslib/dt_common.c | 31 |
2 files changed, 34 insertions, 28 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index db0a6487acf..0a12a9b2e17 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -3569,24 +3569,27 @@ DateTimeParseError(int dterr, const char *str, const char *datatype) static const datetkn * datebsearch(const char *key, const datetkn *base, int nel) { - const datetkn *last = base + nel - 1, - *position; - int result; - - while (last >= base) + if (nel > 0) { - position = base + ((last - base) >> 1); - result = key[0] - position->token[0]; - if (result == 0) + const datetkn *last = base + nel - 1, + *position; + int result; + + while (last >= base) { - result = strncmp(key, position->token, TOKMAXLEN); + position = base + ((last - base) >> 1); + result = key[0] - position->token[0]; if (result == 0) - return position; + { + result = strncmp(key, position->token, TOKMAXLEN); + if (result == 0) + return position; + } + if (result < 0) + last = position - 1; + else + base = position + 1; } - if (result < 0) - last = position - 1; - else - base = position + 1; } return NULL; } diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index da3224aae31..45f1f8affd5 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -512,24 +512,27 @@ char *pgtypes_date_months[] = {"January", "February", "March", "April", "May" static datetkn * datebsearch(char *key, datetkn *base, unsigned int nel) { - datetkn *last = base + nel - 1, - *position; - int result; - - while (last >= base) + if (nel > 0) { - position = base + ((last - base) >> 1); - result = key[0] - position->token[0]; - if (result == 0) + datetkn *last = base + nel - 1, + *position; + int result; + + while (last >= base) { - result = strncmp(key, position->token, TOKMAXLEN); + position = base + ((last - base) >> 1); + result = key[0] - position->token[0]; if (result == 0) - return position; + { + result = strncmp(key, position->token, TOKMAXLEN); + if (result == 0) + return position; + } + if (result < 0) + last = position - 1; + else + base = position + 1; } - if (result < 0) - last = position - 1; - else - base = position + 1; } return NULL; } |