Designing a better strcpy
I hate to nitpick on something so mundane and superficial, but why in the world are people still writing code like this in 2020?<p><pre><code>  while (--len &amp;&amp; (*dst++ = *src++))
    ;
</code></pre>
Dereferenced post-increments are already confusing enough as-is, and yet here we have 1 pre-increment and 2 <i>dereferenced</i> <i>post</i>-increments happening on <i>top</i> of an assignment in a <i>conditional</i>, all in a single expression. Even as someone who <i>does</i> put an assignment in a conditional once in a while, this still feels 100% unjustifiable to me. It&#x27;s especially ironic given the premise is that C code has security bugs... if the goal is to avoid that, shouldn&#x27;t there be even <i>more</i> care taken to avoid this kind of code?<p>EDIT: For those who don&#x27;t think the readability can be improved... any thoughts on something more like this? Do we really need a compound assignment with three side effects in a conditional modifying the function arguments to make this readable?<p><pre><code>  char *strxcpy(char *restrict dst, const char *restrict src, size_t len) {
    size_t i;
    for (i = 0; i &lt; len; ++i) {
      if (src[i] == &#x27;\0&#x27;) { break; }
      dst[i] = src[i];
    }
    int input_exhausted = i &lt; len;
    if (input_exhausted) { ++i; }
    if (i &gt; 0) { dst[i - 1] = &#x27;\0&#x27;; }
    return input_exhausted ? &amp;dst[i] : NULL;
  }</code></pre>