|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.154 2010/01/02 16:57:53 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.155 2010/01/12 02:39:22 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -1680,9 +1680,9 @@ convert_aclright_to_string(int aclright)
|
1680 | 1680 | Datum
|
1681 | 1681 | aclexplode(PG_FUNCTION_ARGS)
|
1682 | 1682 | {
|
| 1683 | + Acl *acl = PG_GETARG_ACL_P(0); |
1683 | 1684 | FuncCallContext *funcctx;
|
1684 | 1685 | int *idx;
|
1685 |
| - Acl *acl = PG_GETARG_ACL_P(0); |
1686 | 1686 | AclItem *aidat;
|
1687 | 1687 |
|
1688 | 1688 | if (SRF_IS_FIRSTCALL())
|
@@ -1722,34 +1722,36 @@ aclexplode(PG_FUNCTION_ARGS)
|
1722 | 1722 |
|
1723 | 1723 | funcctx = SRF_PERCALL_SETUP();
|
1724 | 1724 | idx = (int *) funcctx->user_fctx;
|
1725 |
| - |
1726 | 1725 | aidat = ACL_DAT(acl);
|
1727 |
| - while (1) |
| 1726 | + |
| 1727 | + /* need test here in case acl has no items */ |
| 1728 | + while (idx[0] < ACL_NUM(acl)) |
1728 | 1729 | {
|
| 1730 | + AclItem *aidata; |
| 1731 | + AclMode priv_bit; |
| 1732 | + |
1729 | 1733 | idx[1]++;
|
1730 | 1734 | if (idx[1] == N_ACL_RIGHTS)
|
1731 | 1735 | {
|
1732 | 1736 | idx[1] = 0;
|
1733 | 1737 | idx[0]++;
|
1734 |
| - if (idx[0] == ACL_NUM(acl)) |
1735 |
| - /* done */ |
| 1738 | + if (idx[0] >= ACL_NUM(acl)) /* done */ |
1736 | 1739 | break;
|
1737 | 1740 | }
|
| 1741 | + aidata = &aidat[idx[0]]; |
| 1742 | + priv_bit = 1 << idx[1]; |
1738 | 1743 |
|
1739 |
| - Assert(idx[0] < ACL_NUM(acl)); |
1740 |
| - Assert(idx[1] < N_ACL_RIGHTS); |
1741 |
| - |
1742 |
| - if (ACLITEM_GET_PRIVS(aidat[idx[0]]) & (1 << idx[1])) |
| 1744 | + if (ACLITEM_GET_PRIVS(*aidata) & priv_bit) |
1743 | 1745 | {
|
1744 | 1746 | Datum result;
|
1745 | 1747 | Datum values[4];
|
1746 | 1748 | bool nulls[4];
|
1747 | 1749 | HeapTuple tuple;
|
1748 | 1750 |
|
1749 |
| - values[0] = ObjectIdGetDatum(aidat[idx[0]].ai_grantor); |
1750 |
| - values[1] = ObjectIdGetDatum(aidat[idx[0]].ai_grantee); |
1751 |
| - values[2] = CStringGetTextDatum(convert_aclright_to_string(1 << idx[1])); |
1752 |
| - values[3] = BoolGetDatum(ACLITEM_GET_GOPTIONS(aidat[idx[0]]) & (1 << idx[1])); |
| 1751 | + values[0] = ObjectIdGetDatum(aidata->ai_grantor); |
| 1752 | + values[1] = ObjectIdGetDatum(aidata->ai_grantee); |
| 1753 | + values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit)); |
| 1754 | + values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0); |
1753 | 1755 |
|
1754 | 1756 | MemSet(nulls, 0, sizeof(nulls));
|
1755 | 1757 |
|
|
0 commit comments