RDEBUG4("Copying %zu bytes to %p from offset %zu",
fr_value_box_field_sizes[dst_type], *((void **)out), fr_value_box_offsets[dst_type]);
- memcpy(out, ((uint8_t const *) from_cast) + fr_value_box_offsets[dst_type], fr_value_box_field_sizes[dst_type]);
+ fr_value_box_memcpy_out(out, from_cast, dst_type);
return from_cast->vb_length;
}
RDEBUG4("Copying %zu bytes to %p from offset %zu",
fr_value_box_field_sizes[dst_type], *((void **)out), fr_value_box_offsets[dst_type]);
- memcpy(out, ((uint8_t *)&from_cast) + fr_value_box_offsets[dst_type], fr_value_box_field_sizes[dst_type]);
+ fr_value_box_memcpy_out(out, &from_cast, dst_type);
/*
* Frees any memory allocated for temporary buffers
case FR_TYPE_ETHERNET:
case FR_TYPE_UINT8:
case FR_TYPE_INT8:
- FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, ((uint8_t const *)value) + fr_value_box_offsets[value->type], min);
+ FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, fr_value_box_raw(value, value->type), min);
break;
/*
fr_value_box_hton(&tmp, value);
- FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, ((uint8_t const *)&tmp) + fr_value_box_offsets[value->type], min);
+ FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, fr_value_box_raw(&tmp, value->type), min);
}
break;
case FR_TYPE_IFID:
case FR_TYPE_ETHERNET:
- FR_DBUFF_OUT_MEMCPY_RETURN(((uint8_t *)dst) + fr_value_box_offsets[type], &work_dbuff, len);
+ FR_DBUFF_OUT_MEMCPY_RETURN(fr_value_box_raw(dst, type), &work_dbuff, len);
break;
case FR_TYPE_UINT8:
fr_value_box_hton(&tmp, src); /* Flip any numeric representations */
return fr_value_box_memdup(ctx, dst, dst_enumv,
- ((uint8_t const *)&tmp) + fr_value_box_offsets[src->type],
+ fr_value_box_raw(&tmp, src->type),
fr_value_box_field_sizes[src->type], src->tainted);
}
default:
/* Not the same talloc_memdup call as above. The above memdup reads data from the dst */
return fr_value_box_memdup(ctx, dst, dst_enumv,
- ((uint8_t const *)src) + fr_value_box_offsets[src->type],
+ fr_value_box_raw(src, src->type),
fr_value_box_field_sizes[src->type], src->tainted);
}
}
default:
#ifdef WORDS_BIGENDIAN
memcpy(((uint8_t *)&tmp) + (sizeof(tmp) - len),
- ((uint8_t const *)src) + fr_value_box_offsets[src->type], len);
+ fr_value_box_raw(src, src->type), len);
#else
- memcpy(&tmp, ((uint8_t const *)src) + fr_value_box_offsets[src->type], len);
+ memcpy(&tmp, fr_value_box_raw(src, src->type), len);
#endif
break;
}
default:
#ifdef WORDS_BIGENDIAN
- memcpy(((uint8_t *)dst) + fr_value_box_offsets[dst_type],
+ memcpy(fr_value_box_raw(dst, dst->type),
((uint8_t *)&tmp) + (sizeof(tmp) - len), fr_value_box_field_sizes[dst_type]);
#else
- memcpy(((uint8_t *)dst) + fr_value_box_offsets[dst_type],
+ memcpy(fr_value_box_raw(dst, dst->type),
&tmp, fr_value_box_field_sizes[dst_type]);
#endif
break;
{
switch (src->type) {
default:
- memcpy(((uint8_t *)dst) + fr_value_box_offsets[src->type],
- ((uint8_t const *)src) + fr_value_box_offsets[src->type],
- fr_value_box_field_sizes[src->type]);
+ fr_value_box_memcpy_out(fr_value_box_raw(dst, src->type), src, src->type);
fr_value_box_copy_meta(dst, src);
break;
{
switch (vb->type) {
case FR_TYPE_FIXED_SIZE:
- return fr_hash(((uint8_t const *)vb) + fr_value_box_offsets[vb->type],
- fr_value_box_field_sizes[vb->type]);
+ return fr_hash(fr_value_box_raw(vb, vb->type),
+ fr_value_box_field_sizes[vb->type]);
case FR_TYPE_STRING:
return fr_hash(vb->vb_strvalue, vb->vb_length);
return fr_value_box_alloc(ctx, FR_TYPE_NULL, NULL, false);
}
+/** Return a pointer to the "raw" value from a value-box.
+ *
+ * This has "const" input and "unconst" output because sometimes it's used
+ * to copy out of, and sometimes in to, a value-box. We rely on the caller to know
+ * the correct uses of it.
+ */
+static inline CC_HINT(always_inline)
+uint8_t *fr_value_box_raw(fr_value_box_t const *vb, fr_type_t type)
+{
+ return UNCONST(uint8_t *, vb) + fr_value_box_offsets[type];
+}
+
+/** Copy raw values out of a value box
+ *
+ */
+static inline CC_HINT(always_inline)
+void fr_value_box_memcpy_out(void *dst, fr_value_box_t const *vb, fr_type_t type)
+{
+ memcpy(dst, ((uint8_t const *)vb) + fr_value_box_offsets[type], fr_value_box_field_sizes[type]);
+}
+
+
/** Box an ethernet value (6 bytes, network byte order)
*
* @param[in] dst Where to copy the ethernet address to.