Actions
Bug #3504
closedwformat and long printing
Start date:
08/28/2018
Due date:
% Done:
100%
Spec Reference:
Description
https://git.osmocom.org/simtrace2/commit/?id=c394109964a18d05d46de46728f617465f3493c4 enabled Wformat compiler errors.
This for example warns about the following:
./atmel_softpack_libraries/libchip_sam3s/include/trace.h:187:40: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'RoReg' {aka 'const volatile long unsigned int'} [-Wformat=] #define TRACE_INFO(...) { printf("-I- " __VA_ARGS__); } ^~~~~~ apps/trace/main.c:168:2: note: in expansion of macro 'TRACE_INFO' TRACE_INFO("Chip ID: 0x%08x (Ext 0x%08x)\n\r", CHIPID->CHIPID_CIDR, CHIPID->CHIPID_EXID); ^~~~~~~~~~ apps/trace/main.c:168:28: note: format string is defined here TRACE_INFO("Chip ID: 0x%08x (Ext 0x%08x)\n\r", CHIPID->CHIPID_CIDR, CHIPID->CHIPID_EXID); ~~~^ %08lx
RoReg is defined as follows:
53:typedef volatile const uint32_t RoReg; /**< Read only 32-bit register (volatile const unsigned int) */
SAM3S is a 32-bit platform, where int and long both correspond to 32-bit integers.
gcc says uint32_t correspond to unsigned long because is is defined as being at least 16-bit long, while long is defined as being at least 32-bit long.
Because RoReg is now considered as long, Wformat recommends to use "%l" (in out case %lx".
the atmel printf does not provide %l support:
libcommon/source/stdio.c vsnprintf
// Normal character
if (*pFormat != '%') {
*pStr++ = *pFormat++;
size++;
}
// Escaped '%'
else if (*(pFormat+1) == '%') {
*pStr++ = '%';
pFormat += 2;
size++;
}
// Token delimiter
else {
fill = ' ';
width = 0;
pFormat++;
// Parse filler
if (*pFormat == '0') {
fill = '0';
pFormat++;
}
// Parse width
while ((*pFormat >= '0') && (*pFormat <= '9')) {
width = (width*10) + *pFormat-'0';
pFormat++;
}
// Check if there is enough space
if (size + width > length) {
width = length - size;
}
// Parse type
switch (*pFormat) {
case 'd':
case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break;
case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break;
case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break;
case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break;
case 's': num = PutString(pStr, va_arg(ap, char *)); break;
case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break;
default:
return EOF;
using %l causes a bug were the previous buffer is reread:
============================================================================= SIMtrace2 firmware 0.4.159-e076-dirty (C) 2010-2016 by Harald Welte ============================================================================= -I- Chip ID: 0x================================================================== SIMtrace2 firmware 0.4.159-e076-dirty (C) 2010-2016 by Harald Welte ============================================================================= -I- Serial Nr. 51203120-38463850-33303231-36313035
laforge should we re-disable Wformat or add (void) %l support to stdio?
Actions