tempesta-tech / tempesta

All-in-one solution for high performance web content delivery and advanced protection against DDoS and web attacks
https://tempesta-tech.com/
GNU General Public License v2.0
615 stars 103 forks source link

Redundant min(src->len, dst->len) in tfw_strcpy() #2245

Closed ai-tmpst closed 1 day ago

ai-tmpst commented 1 week ago

From tfw_strcpy() function in fw/str.c:702:

    if (unlikely(src->len > dst->len))
        return -E2BIG;

    switch (mode) {
    case 3: /* The both are plain. */
        memcpy_fast(dst->data, src->data, min(src->len, dst->len));
        break;

If the condition (src->len > dst->len) is true, it returns an error. Since the condition guarantees that src->len <= dst->len, min(src->len, dst->len) can be simplified to src->len.

krizhanovsky commented 1 day ago

Done in #2247