strncat

strncatは、指定された文字列を指定された文字数分連結する。

Man page of STRCAT
C言語関数辞典 - strncat

文字列が文字数より少なくても多くてもNULL終端はされる模様。


$ vi strncat.c
$ gcc strncat.c -o strncat
strncat.c: 関数 ‘main’ 内:
strncat.c:15:3: 警告: ‘strncat’ specified bound 5 equals source length
[-Wstringop-overflow=]
   strncat(str1, "ABCDE", 5); /* strncatで空文字のstr1に"ABCDE"を連結. */
   ^~~~~~~~~~~~~~~~~~~~~~~~~
$ ./strncat
str1 = ABCDE
str1 = ABCDEFG
str1 = ABCDEFGIJKLM
$

NULL文字('\0')含めない文字数と第3引数が同じだと警告が出るが、含めた文字数を指定しないといけないのかなとおもったが、

c++ - strncat Wformat-overflow warning when using gcc 8.2.1 - Stack Overflow
Third argument of strncat should not be the length of src · Issue #3488 · apache/trafficserver · GitHub

バグ?いや、strcatを呼び出せという警告?バッファは十分だしなあ・・・。

Sample/c/strncat/strncat/src/strncat at master · bg1bgst333/Sample · GitHub