[asterisk-bugs] [JIRA] (ASTERISK-24619) Gcc 4.10 fixes in r413589 (1.8) wrongly casts char to unsigned int
Rusty Newton (JIRA)
noreply at issues.asterisk.org
Mon Dec 15 09:55:29 CST 2014
[ https://issues.asterisk.org/jira/browse/ASTERISK-24619?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rusty Newton updated ASTERISK-24619:
------------------------------------
Component/s: Core/General
> Gcc 4.10 fixes in r413589 (1.8) wrongly casts char to unsigned int
> ------------------------------------------------------------------
>
> Key: ASTERISK-24619
> URL: https://issues.asterisk.org/jira/browse/ASTERISK-24619
> Project: Asterisk
> Issue Type: Bug
> Security Level: None
> Components: Core/General
> Affects Versions: SVN, 1.8.32.1
> Reporter: Walter Doekes
>
> Example:
> {noformat}
> int main() { const char *abc = "åäö"; return (((unsigned) abc[3]) >> 24) == 0 ? 0 : 1; }
> {noformat}
> yields 1
> Or, more visibly:
> {noformat}
> #include <stdio.h>
> int main() {
> const char *abc = "åäö";
> printf("bad: %02X\n", (unsigned)*abc);
> printf("good: %02hhX\n", (unsigned char)*abc);
> return 0;
> }
> {noformat}
> yields:
> {noformat}
> $ ./a.out
> bad: FFFFFFC3
> good: C3
> {noformat}
> Unfortunately, the changes in r413589 introduce just that.
> E.g.:
> {noformat}
> $ svn diff -c 413586 > tmp.diff
> $ grep '^-.*(unsigned char)' tmp.diff -A1
> - sprintf(digest + (idx << 1), "%2.2x", (unsigned char) key[idx]); \
> + sprintf(digest + (idx << 1), "%2.2x", (unsigned) key[idx]); \
> --
> - sprintf(&addrmac[i], "%.2x", (unsigned char) buf[tmp]);
> + sprintf(&addrmac[i], "%.2x", (unsigned) buf[tmp]);
> --
> - sprintf(p, "%02X ", (unsigned char)buf[f]);
> + sprintf(p, "%02X ", (unsigned)buf[f]);
> --
> - out += sprintf(out, "%%%02X", (unsigned char) *ptr);
> + out += sprintf(out, "%%%02X", (unsigned) *ptr);
> {noformat}
> That's wrong, the compiler warnings should have been fixed using the hh (char) modifier: {{%02hhX}}
> Issue was reported by stefan27 via IRC.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
More information about the asterisk-bugs
mailing list