[hipl-dev] Re: [Merge] lp:~midauth-pisa-devs/hipl/midauth-firewall into lp:hipl

  • From: Christof Mroz <christof.mroz@xxxxxxxxxxxxxx>
  • To: hipl-dev@xxxxxxxxxxxxx
  • Date: Wed, 19 Oct 2011 22:56:18 +0200

On 19.10.2011 18:42, René Hummen wrote:

>> +/**
>> + * TODO comment
>> + */
>> +static void *rebase(const void *const field,
>> +                    const void *const old,
>> +                    void *const new)
>> +{
>> +    HIP_ASSERT((const char *) field>= (const char *) old);
>> +    return (char *) new + ((const char *) field - (const char *) old);
>> +}
>
> @Christof: Can you please provide me with the doxygen comment for this
> function. I don't completely understand what it is doing.

Sure:

/**
 * Given the address @a field of a struct member of @a old, return
 * the same field's address but offset from @a new.
 *
 * As an example use case, say we have a pointer into @a old:
 * <code>
 * char old[LEN];
 * ptr = &old[BLA];
 * </code>
 * Now after copying @a old to @a new, we need to update the pointer:
 * <code>
 * ptr = rebase(ptr, old, new);
 * </code>
 *
 * @note This is essentially equivalent to
 *       <code>
 *       return &new.field
 *       </code>
 *       But of course, the above can only be used if we actually know
 *       the name of @a field, while this function needs just the
 *       address and base pointer.
 */
static void *rebase(const void *const field,
                    const void *const old,
                    void *const new)
{
    HIP_ASSERT((const char *) field>= (const char *) old);
    return (char *) new + ((const char *) field - (const char *) old);
}

As far as I remember, the note inside this doxygen comment didn't apply to the specific cases in the midauth code (because the ipq packet buffer has no structure). But if you think I'm mistaken then get rid of this function by any means.

I'm looking forward to reviewing this branch, but it's quite long and the semester is at full throttle already so it could take a while.

Other related posts: