<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/83730>83730</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            No warning reported for buffer overflow in Clang
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mushenoy
      </td>
    </tr>
</table>

<pre>
    Buffer overflow in the below scenario is not detected in Clang. 
GCC reports warning for the same program.

Sample program
```
#include <string.h>

char d[3];
void test (int i)
{
  const char *s = i < 0 ? "12345678" : "87654321";
  strcat (d, s);
}
```

Compilation with Clang:
No warnings reported
```
# clang -c -Wall prog.c
#
```

Compilation with GCC:
```
# gcc -c -Wall prog.c
prog.c: In function test:
prog.c:7:3: warning: strcat writing 9 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=]
    7 |   strcat (d, s);
      |   ^~~~~~~~~~~~~
prog.c:3:6: note: destination object d of size 3
    3 | char d[3];
      |      ^
```

Compiler Versions:
```
clang version 16.0.6 
gcc (GCC) 13.2.1
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2PqzYU_TWXzVUQ2BDDgkVCXp666aZS39qYC7gidmSbGU0X_e2VgcmM2kyrhxAfvsfnfp1r6b0eDVED5RnKSyKXMFnX3BY_kbFvSWf7t-a8DAM5tC_khtm-ojYYJsKO4o9XZKTTFrVHYwP2FEgF6iOqnaUZU4TsAtnpe9uio7t1weOrdEabEQfrViovb4R3Z0cnb-kG356_ydt9fph2yzHb7-2XcW3UvPSEwFsfnDZjOgH_9plHTdJhD-WZQ3kBft5WX6zuMZAPCKzSJqAGVu_bxI5BVNb4gCsDsJNH4BfU0RdmCPyKwFjOeFEeRQWMIfBTXKrEsSw4y4Gxhz9EH5ySq7seWIs--nu3grg8T3B9tvZ217MM2hp81WHaigt8N_9q34vq9ypT_1W5UMWteFB4-CHnea1uqh7mnwnie9s-QnjiaFTquZv9m5_wF4PDYtRKGVvxoHtABPATj9A9wfi51_HV6RB1VGP3FsijNsGiREdjpLMDev0nIX9I169q68kHbbYsoDwffmyisffDOw74JepkbxqiQBAt_nf7cL02HJTf_vp0_SOhmMwxZmFsoPj-HJDt_iAVsP-I_oOer_TPtfzZ_RbB__aRHP5Ozmtr_FdN3JTysqEwP6ZZetznOfYWWBUVwGrMecrS_ClH0je8r3ktE2pykdVFVdSFSKZGVIOsBRNKqE6pLlOyyoqu5ENFeVZxkeiGZazIeMbzY1kWIh1I1EelMqF4TsQVFBndpJ7TeX65pdaNifZ-oabigmfJLDua_Xq0MbZmEoexvCSuifhDt4weimzWPvgPhqDDTM3HPD3GaT2tun-fhesgJoubmymE-1pKdgV2HXWYli5V9gbsGun31-HubOwxsOsarQd2XQP-OwAA__8r_ptG">