警告warning: strncpy specified bound XX equals destination size
生活随笔
收集整理的這篇文章主要介紹了
警告warning: strncpy specified bound XX equals destination size
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、問題
用strncpy字符串拷貝時,出現警告:warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]。
2、解決:strncpy不拷貝最后一個字節,手動給它賦值'\0'。
例子: #define SIZE = 20; char *a_str = "12345678"; char mybuff[SIZE]; strncpy(mybuff, a_str, SIZE-1); mybuff[size-1] = '\0';就不會報錯了。
總結
以上是生活随笔為你收集整理的警告warning: strncpy specified bound XX equals destination size的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bmp 像素点 php,读取BMP图像每
- 下一篇: 如何实现和提升软件易用性