*** pgsql/src/backend/utils/adt/varbit.c 2009/12/12 19:25:10 1.44.4.2 --- pgsql/src/backend/utils/adt/varbit.c 2010/01/07 19:53:39 1.44.4.3 *************** *** 9,15 **** * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.44.4.1 2007/08/21 02:40:26 tgl Exp $ * *------------------------------------------------------------------------- */ --- 9,15 ---- * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.44.4.2 2009/12/12 19:25:10 tgl Exp $ * *------------------------------------------------------------------------- */ *************** bitsubstr(PG_FUNCTION_ARGS) *** 807,819 **** *ps; bitlen = VARBITLEN(arg); - /* If we do not have an upper bound, set bitlen */ - if (l == -1) - l = bitlen; - e = s + l; s1 = Max(s, 1); ! e1 = Min(e, bitlen + 1); ! if (s1 > bitlen || e1 < 1) { /* Need to return a zero-length bitstring */ len = VARBITTOTALLEN(0); --- 807,829 ---- *ps; bitlen = VARBITLEN(arg); s1 = Max(s, 1); ! /* If we do not have an upper bound, use end of string */ ! if (l < 0) ! { ! e1 = bitlen + 1; ! } ! else ! { ! e = s + l; ! /* guard against overflow, even though we don't allow L<0 here */ ! if (e < s) ! ereport(ERROR, ! (errcode(ERRCODE_SUBSTRING_ERROR), ! errmsg("negative substring length not allowed"))); ! e1 = Min(e, bitlen + 1); ! } ! if (s1 > bitlen || e1 <= s1) { /* Need to return a zero-length bitstring */ len = VARBITTOTALLEN(0);