NuttX
NuttX copied to clipboard
Buggy handling of unsigned long in vsprintf_internal
When compiling the code on a machine which has unsigned long defined as 8 bytes, the buggy code here will mark the second branch as duplicate branch since on x86-64 bit machines, unsigned long and unsigned long long have the same size, ie, 8 bytes.
case sizeof(unsigned long):
c = 'l';
break;
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
case sizeof(unsigned long long):
c = 'l';
flags |= FL_LONG;
flags &= ~FL_SHORT;
break;
#endif
A relatively simple fix would be to have the case for unsigned long in the #else
branch of the #if
.
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
case sizeof(unsigned long long):
c = 'l';
flags |= FL_LONG;
flags &= ~FL_SHORT;
break;
#else
case sizeof(unsigned long):
c = 'l';
break;
#endif
This should fix the issue of duplicate branch.
@PwnVerse Please submit a PR upstream.