[Home]

Summary:ASTERISK-24619: [patch]Gcc 4.10 fixes in r413589 (1.8) wrongly casts char to unsigned int
Reporter:Walter Doekes (wdoekes)Labels:
Date Opened:2014-12-15 07:30:47.000-0600Date Closed:2014-12-17 03:28:11.000-0600
Priority:MajorRegression?Yes
Status:Closed/CompleteComponents:Core/General
Versions:SVN 1.8.32.1 Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description: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.
Comments: