There's this code I'm compling, which has the line:
snprintf(target, 11, "%02ld-%02ld-19%02ld", day, month, year);
... which is executed after it has been verified that all 3 values are valid; and specifically, that year is between 0 and 99.
However, recent versions of GCC, when run with -Wextra
, complain:
warning: ‘%02ld’ directive output may be truncated writing between 2 and 20 bytes
into a region of size 3 [-Wformat-truncation=]
I would rather not entirely disable this warning; nor even disable it locally. Instead, I am wondering if I could somehow "convince" GCC of the value range for the three arguments, preventing the warning.
Yes, this is rather ugly code that reinvents the wheel, and locale-specific routines for date formatting should be used, no need to lecture me; not my code.