Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of hex char literals in device tree source format #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

StekiKun
Copy link

@StekiKun StekiKun commented Jul 16, 2022

The format specifier PRIx8 for unsigned integers was used with a
signed character parameter, yielding unexpected results with values > 0x7F.

If you run for instance dtc -I dts -O dts tests/escapes.dts, you can notice
that the value of the escape-str-2 property, which is initially "\xde\xad\xbe\xef", is not
printed correctly:

/dts-v1/;

/ {
	compatible = "test_string_escapes";
	escape-str = "nastystring: \a\b\t\n\v\f\r\\\"";
	escape-str-2 = "\xffffffde\xffffffad\xffffffbe\xffffffef";
};

This happens because the signed character is type-converted to an int, which should not be used with the %x format specifier.
I fixed this by casting to an unsigned char; another possible way is to add hh to the format specifier but I find the former more self-explanatory.

For a bit of context, I found this as I was attempting to "canonize" DTS files by running dtc -I dts -O dts until it reached a fix-point (it so happens that resolution of path and label refs leave an extra space -- due to the markers -- in data blobs, so one must run dtc twice on a file to reach a stable result).

The format specifier PRIx8 for unsigned integers was used with a
signed character, yielding unexpected results with values >= 0x7F.
@dgibson
Copy link
Owner

dgibson commented Jul 30, 2022

Fix looks good, but I'll need a Signed-off-by line as described in the new CONTRIBUTING.md file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants