snprintfに関連するwarningに対処する
-Wformatの下記
-Wformat-overflow=1
-Wformat-truncation=1
code:memo
#define snprintf_trunc(dst, size, ...) \
do { \
volatile size_t n = size; \
snprintf (dst, n, __VA_ARGS__); \
} while (0)
ref: 89312 – snprintf warning is unparsable and not confusing
code:c
int anint = 42;
char buf42;
n = snprintf(lenbuf, sizeof(lenbuf), "%d:", anint);
if (!(n > -1 && n < sizeof(lenbuf))) {
perror("snprintf");
return -1;
}
ref: snprintf error handling
関連
C言語 ファイル操作
参考
c - How to circumvent format-truncation warning in GCC? - Stack Overflow
The trouble with snprintf
snprintf error handling
メモ