Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

The format specifier of std::sprintf is incorrect #1192

Open
lm-kasuga opened this issue Sep 1, 2020 · 0 comments · Fixed by #1199
Open

The format specifier of std::sprintf is incorrect #1192

lm-kasuga opened this issue Sep 1, 2020 · 0 comments · Fixed by #1199

Comments

@lm-kasuga
Copy link
Contributor

The variable len is int, but %u is used.
This may cause UB(but the compiler doesn't say any errors or warnings. ref. https://stackoverflow.com/questions/11303784/why-doesnt-gcc-wformat-warn-about-printf-d-on-an-unsigned-int)
We should use %d instead, or change the type of len to unsigned int.
Using other C++ STL (like std::stringstream) is also good, I think.

std::sprintf(buf, "%c%c%u", c_endian, c_type, len);

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

Successfully merging a pull request may close this issue.

1 participant