This code
struct tm boot_time;
char dtbuf [20];
getrtc (&boot_time);
snprintf( dtbuf,16,"%02d%02d%04d %02d%02d%02d", \
boot_time.tm_mday, boot_time.tm_mon+1, boot_time.tm_year+1900, \
boot_time.tm_hour, boot_time.tm_min, boot_time.tm_sec );
dtbuf[15]=0; // just in case
is generating a warning:
'%02d' directive writing between 2 and 11 bytes into a region of size between 0 and 14 [-Wformat-overflow=]
Lots of people have been up this path and clearly outputting an int (which in ARM32GCC is defined as 16 bits, believe it or not, not 32) %02d is the problem because it can generate 5 digits, even though the actual value cannot be bigger than say 31 for day of month.
So I changed it to limit the values explicitly
(boot_time.tm_mday)%32, (boot_time.tm_mon+1)%13, (boot_time.tm_year+1900)%2099, \
(boot_time.tm_hour)%24, (boot_time.tm_min)%60, (boot_time.tm_sec)%60 );
but the compiler is not realising that e.g. the MOD 32 is limiting the range to 2 digits.
What is the cleanest way to fix this (without a command line option to suppress the warning)?
The final string being generated is
15042022 204415
i.e. ddmmyyyy hhmmss
EDIT: I found that using %02u instead of %02d suppresses the warnings, but I can't see how. Using a much bigger buffer probably also works.