Re: Modifying the modification
Howard Chu <[email protected]> Fri, 13 Feb 2026 13:03:22 +0000
| Newsgroups | gmane.network.openldap.devel |
|---|---|
| Message-ID | <[email protected]> |
Emmanuel Dreyfus wrote:
> On Thu, Feb 12, 2026 at 03:25:33PM +0000, Howard Chu wrote:
>> Modify is fine. For add, you should use attr_free(), not attr_clean() + free().
>
> Thank you for the review.
>
> I also have the need toremove a single attribute value for modify or add.
> I wonder if I need to take care of SLAP_ATTR_DONT_FREE_DATA and
> SLAP_ATTR_DONT_FREE_VALS in the add caze.
This all looks fine. But you should think about what happens if the attribute
has no values remaining after you do your removal.
>
> static void
> supann_attr_rmval(Attribute *a, int index)
> {
> struct berval *nbv;
> int j;
>
> nbv = &a->a_vals[index];
> ber_memfree_x(nbv->bv_val, NULL);
> nbv->bv_val = NULL;
>
> if (a->a_nvals && a->a_nvals != a->a_vals) {
> nbv = &a->a_nvals[index];
> ber_memfree_x(nbv->bv_val, NULL);
> nbv->bv_val = NULL;
> }
>
> a->a_numvals--;
>
> /*
> * a->a_vals[j + 1] does not overflow since
> * we just decreased a->a_numvals
> */
> for (j = index; j < a->a_numvals; j++)
> a->a_vals[j] = a->a_vals[j + 1];
>
> a->a_vals[a->a_numvals].bv_val = NULL;
> a->a_vals[a->a_numvals].bv_len = 0;
>
> if (a->a_nvals && a->a_nvals != a->a_vals) {
> for (j = index; j < a->a_numvals; j++)
> a->a_nvals[j] = a->a_nvals[j + 1];
>
> a->a_nvals[a->a_numvals].bv_val = NULL;
> a->a_nvals[a->a_numvals].bv_len = 0;
> }
>
> return;
> }
>
>
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/