You're counting one more join than you actually need.  You're also calling strlen(join) every time round the loop, which is inefficient.  Simply counting the number of non-CF_NULL entries in the list (while summing their entries in size) would suffix; you can then: size += (count - 1) * strlen(join); once after the loop to get the right value and only call strlen(join) once.