NuttX icon indicating copy to clipboard operation
NuttX copied to clipboard

Buggy handling of unsigned long in vsprintf_internal

Open PwnVerse opened this issue 1 year ago • 1 comments

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 avatar Oct 18 '23 21:10 PwnVerse

@PwnVerse Please submit a PR upstream.

davids5 avatar Oct 19 '23 05:10 davids5