Skip to content

newlib: PRIx8 inttype incorrectly resolves to hh with newlib-nano #45336

@stephanosio

Description

@stephanosio

Describe the bug
The hh format modifier (e.g. %hhu), which is used for the [u]int8_t types, is not supported by the Zephyr SDK newlib-nano build because the nano variant builds without the _WANT_IO_C99_FORMATS option:

		case 'h':
#ifdef _WANT_IO_C99_FORMATS
			if (*fmt == 'h') {
				fmt++;
				flags |= CHARINT;
			} else
#endif

Noting that the newlib-nano build does not support the hh modifier, the PRIx8 inttypes should not resolve to hh*; instead, they should resolve to one of the closest types (e.g. h*).

To Reproduce

Run the following code with CONFIG_NEWLIB_LIBC=y and CONFIG_NEWLIB_LIBC_NANO=y:

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

void main(void)
{
        volatile uint8_t a = 92;
        volatile uint8_t b = 254;
        volatile uint16_t c = 4883;

        printf("%hhu.%hhu.%hu\n", a, b, c);
        printf("%%" PRIu8 "\n");
}

Because the hh modifier is not supported with the newlib-nano, the output is as follows:

hu.hu.92
%hhu

Note that PRIu8 resolves to hhu, which is not supported; thereby, rendering PRIx8 inttypes unusable with the newlib-nano.

Expected behavior

When CONFIG_NEWLIB_LIBC_NANO=y, PRIx8 inttypes resolve to %h*, which is the closest to %hh*.

Impact

PRIx8 inttypes are unusable with the newlib-nano.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Toolchain: Zephyr SDK 0.14.1
  • Commit SHA: d5e7732

Additional context

  • This problem was originally reported and discussed in Fix version string formatting #45329 (comment)
  • The exact same problem is observed with the GNU Arm Embedded toolchain (because the Zephyr SDK has tried to replicate the GNU Arm Embedded build configurations until now).

Metadata

Metadata

Assignees

Labels

area: C LibraryC Standard Libraryarea: newlibNewlib C Standard LibrarybugThe issue is a bug, or the PR is fixing a bugpriority: highHigh impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions