- if (reference_count == nelem(referenced_ids))
- {
- memmove(referenced_ids + 1, referenced_ids + 2,
- sizeof(referenced_ids) - 2*sizeof(uschar *));
- referenced_ids[reference_count - 1] = id;
- }
+ {
+ unsigned this = Ustrlen(id);
+ if ( reference_count == nelem(referenced_ids)
+ || use + this + reference_count > 998
+ )
+ {
+ if (reference_count > 1)
+ {
+ /* drop position 1 and shuffle down */
+ use -= Ustrlen(referenced_ids + 1);
+ memmove(referenced_ids + 1, referenced_ids + 2,
+ sizeof(referenced_ids) - 2*sizeof(*referenced_ids));
+
+ /* append new one */
+ referenced_ids[reference_count - 1] = id;
+ }
+ }