-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
static_cast char to unsigned on BIG_ENDIAN platforms may cause errors #41
Comments
Comment #1 originally posted by gabor@google.com on 2011-09-23T22:58:32.000Z: Thanks for this! Could you please try out the patch here: And see if that fixes your problem? Let me know - thanks, Gabor |
Comment #2 originally posted by Alexander.Klishin on 2011-09-30T11:20:01.000Z: This patch fixes problem. My platform is HP-UX 11.31 ia64 |
Comment #3 originally posted by gabor@google.com on 2011-10-05T23:28:00.000Z: This issue was closed by revision e028bdf. |
Comment #4 originally posted by gabor@google.com on 2011-10-05T23:31:07.000Z: This issue was closed by revision 299cced. |
Comment #5 originally posted by gabor@google.com on 2011-10-05T23:35:06.000Z: This issue was closed by revision r53. |
Comment #6 originally posted by dgrogan@chromium.org on 2012-06-01T23:55:51.000Z: Issue 36 has been merged into this issue. |
Original issue 35 created by Alexander.Klishin on 2011-08-23T06:31:19.000Z:
util/coding_test may fail on some BIG_ENDIAN platforms
uname -ms
HP-UX ia64
gcc version 4.3.3 (GCC)
micro test:
====cast.cpp ====
include <stdio.h>
int main(int ac, char *av[]) {
char c = -1;
printf("cast1=%u cast2=%u",
static_cast<unsigned int>(c), //!!! wrong conversion
static_cast<unsigned int>(static_cast<unsigned char>(c)));
}
g++ cast.cpp -o cast
./cast
cast1=4294967295 cast2=255
Problem in file "util\coding.h"
inline uint32_t DecodeFixed32(const char* ptr) {
...
return ((static_cast<uint32_t>(ptr[0]))
| (static_cast<uint32_t>(ptr[1]) << 8)
| (static_cast<uint32_t>(ptr[2]) << 16)
| (static_cast<uint32_t>(ptr[3]) << 24));
}
Should be:
return ((static_cast<uint32_t>(static_cast<unsigned char>(ptr[0])))
| (static_cast<uint32_t>(static_cast<unsigned char>(ptr[1])) << 8)
| (static_cast<uint32_t>(static_cast<unsigned char>(ptr[2])) << 16)
| (static_cast<uint32_t>(static_cast<unsigned char>(ptr[3])) << 24));
The text was updated successfully, but these errors were encountered: