Fix printf problems with high ascii characters after r413586 (1.8).

In r413586 (1.8) various casts were added to silence gcc 4.10 warnings.
Those fixes included things like:

    -out += sprintf(out, "%%%02X", (unsigned char) *ptr);
    +out += sprintf(out, "%%%02X", (unsigned) *ptr);

That works for low ascii characters, but for the high range that yields
e.g. FFFFFFC3 when C3 is expected.

This changeset:
- fixes those casts to use the 'hh' unsigned char modifier instead
- consistently uses %02x instead of %2.2x (or other non-standard usage)
- adds a few 'h' modifiers in various places
- fixes a 'replcaes' typo
- dev/urandon typo (in 13+ patch)

Review: https://reviewboard.asterisk.org/r/4263/

ASTERISK-24619 #close
Reported by: Stefan27 (on IRC)
........

Merged revisions 429673 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 429674 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@429675 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Walter Doekes
2014-12-17 09:54:00 +00:00
parent a3534b7c05
commit 9ae57e0dd6
25 changed files with 88 additions and 90 deletions

View File

@@ -1456,7 +1456,7 @@ static void dump_message(char *type, char *vname, unsigned char *buf, int buflen
int x;
printf("%s %s: [ ", type, vname);
for (x = 0; x < buflen; x++)
printf("%02x ", buf[x]);
printf("%02hhx ", buf[x]);
printf("]\n");
}
#endif

View File

@@ -87,9 +87,8 @@ static int cpeid_exec(struct ast_channel *chan, const char *idata)
res = ast_adsi_get_cpeid(chan, cpeid, 0);
if (res > 0) {
gotcpeid = 1;
ast_verb(3, "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n",
(unsigned)cpeid[0], (unsigned)cpeid[1], (unsigned)cpeid[2],
(unsigned)cpeid[3], ast_channel_name(chan));
ast_verb(3, "Got CPEID of '%02hhx:%02hhx:%02hhx:%02hhx' on '%s'\n",
cpeid[0], cpeid[1], cpeid[2], cpeid[3], ast_channel_name(chan));
}
if (res > -1) {
strcpy(data[1], "Measuring CPE...");
@@ -103,9 +102,8 @@ static int cpeid_exec(struct ast_channel *chan, const char *idata)
}
if (res > -1) {
if (gotcpeid)
snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x",
(unsigned)cpeid[0], (unsigned)cpeid[1],
(unsigned)cpeid[2], (unsigned)cpeid[3]);
snprintf(data[1], 80, "CPEID: %02hhx:%02hhx:%02hhx:%02hhx",
cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
else
strcpy(data[1], "CPEID Unknown");
if (gotgeometry)

View File

@@ -1425,7 +1425,9 @@ static int osp_uuid2str(
int res;
if ((uuid != NULL) && (bufsize > OSP_SIZE_UUIDSTR)) {
snprintf(buffer, bufsize, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
snprintf(buffer, bufsize, "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-"
"%02hhx%02hhx-%02hhx%02hhx-"
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
res = OSP_OK;

View File

@@ -783,7 +783,7 @@ static void sms_log(sms_t * h, char status)
unsigned char n;
if (h->mr >= 0) {
snprintf(mrs, sizeof(mrs), "%02X", (unsigned)h->mr);
snprintf(mrs, sizeof(mrs), "%02hhX", (unsigned char)h->mr);
}
snprintf(line, sizeof(line), "%s %c%c%c%s %s %s %s ",
isodate(time(NULL), buf, sizeof(buf)),
@@ -1016,7 +1016,7 @@ static void sms_writefile(sms_t * h)
unsigned int p;
fprintf(o, "udh#");
for (p = 0; p < h->udhl; p++) {
fprintf(o, "%02X", (unsigned)h->udh[p]);
fprintf(o, "%02hhX", (unsigned char)h->udh[p]);
}
fprintf(o, "\n");
}
@@ -1049,7 +1049,7 @@ static void sms_writefile(sms_t * h)
if (p == h->udl) { /* can write in ucs-1 hex */
fprintf(o, "ud#");
for (p = 0; p < h->udl; p++) {
fprintf(o, "%02X", (unsigned)h->ud[p]);
fprintf(o, "%02hhX", (unsigned char)h->ud[p]);
}
fprintf(o, "\n");
} else { /* write in UCS-2 */
@@ -1140,7 +1140,7 @@ static unsigned char sms_handleincoming (sms_t * h)
return 0xFF; /* duh! */
}
} else {
ast_log(LOG_WARNING, "Unknown message type %02X\n", (unsigned)h->imsg[2]);
ast_log(LOG_WARNING, "Unknown message type %02hhX\n", h->imsg[2]);
return 0xFF;
}
} else { /* client */
@@ -1163,7 +1163,7 @@ static unsigned char sms_handleincoming (sms_t * h)
return 0xFF; /* duh! */
}
} else {
ast_log(LOG_WARNING, "Unknown message type %02X\n", (unsigned)h->imsg[2]);
ast_log(LOG_WARNING, "Unknown message type %02hhX\n", h->imsg[2]);
return 0xFF;
}
}
@@ -1245,7 +1245,7 @@ static char *sms_hexdump(unsigned char buf[], int size, char *s /* destination *
int f;
for (p = s, f = 0; f < size && f < MAX_DEBUG_LEN; f++, p += 3) {
sprintf(p, "%02X ", (unsigned)buf[f]);
sprintf(p, "%02hhX ", (unsigned char)buf[f]);
}
return(s);
}
@@ -1483,7 +1483,7 @@ static void sms_debug (int dir, sms_t *h)
int n = (dir == DIR_RX) ? h->ibytep : msg[1] + 2;
int q = 0;
while (q < n && q < 30) {
sprintf(p, " %02X", (unsigned)msg[q++]);
sprintf(p, " %02hhX", msg[q++]);
p += 3;
}
if (q < n) {