1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Fix a collection of type / format string mismatches.

Ilya Shipitsin sent me a list of errors reported by a tool 'cppcheck',
which I hadn't seen before, together with some fixes for things
already taken off that list. This change picks out all the things from
the remaining list that I could quickly identify as actual errors,
which it turns out are all format-string goofs along the lines of
using a %d with an unsigned int, or a %u with a signed int, or (in the
cases in charset/utf8.c) an actual _size_ mismatch which could in
principle have caused trouble on a big-endian target.
This commit is contained in:
Simon Tatham 2017-06-20 07:05:39 +01:00
parent 892d4a0188
commit 20e36ae4a2
7 changed files with 11 additions and 9 deletions

View File

@ -267,7 +267,7 @@ void utf8_read_test(int line, char *input, int inlen, ...)
}
if (l != str[i]) {
printf("%d: char %d came out as %08x, should be %08x\n",
line, i, str[i], l);
line, i, str[i], (unsigned)l);
total_errs++;
}
}
@ -306,7 +306,7 @@ void utf8_write_test(int line, const long *input, int inlen, ...)
}
if (l != str[i]) {
printf("%d: char %d came out as %08x, should be %08x\n",
line, i, str[i], l);
line, i, str[i], (unsigned)l);
total_errs++;
}
}

View File

@ -445,7 +445,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
if (!strcmp(p, "ENCRYPTED"))
ret->encrypted = TRUE;
} else if (!strcmp(line, "DEK-Info")) {
int i, j, ivlen;
int i, ivlen;
if (!strncmp(p, "DES-EDE3-CBC,", 13)) {
ret->encryption = OP_E_3DES;
@ -459,6 +459,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
}
p = strchr(p, ',') + 1;/* always non-NULL, by above checks */
for (i = 0; i < ivlen; i++) {
unsigned j;
if (1 != sscanf(p, "%2x", &j)) {
errmsg = "expected more iv data in DEK-Info";
goto error;

View File

@ -2014,7 +2014,7 @@ int main(int argc, char **argv)
unsigned long chr = strtoul(argv[i], NULL, 0);
int type = getType(chr);
assert(typetoname[type].type == type);
printf("U+%04x: %s\n", chr, typetoname[type].name);
printf("U+%04x: %s\n", (unsigned)chr, typetoname[type].name);
}
return 0;

3
misc.c
View File

@ -157,7 +157,8 @@ int main(void)
passes++; \
} else { \
printf("fail: %s(%s,%s)%s = %u, expected %u\n", \
#func, #string, #arg2, #suffix, ret, result); \
#func, #string, #arg2, #suffix, ret, \
(unsigned)result); \
fails++; \
} \
} while (0)

2
pscp.c
View File

@ -1476,7 +1476,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
act->action = SCP_SINK_ENDDIR;
return 0;
case 'T':
if (sscanf(act->buf, "%ld %*d %ld %*d",
if (sscanf(act->buf, "%lu %*d %lu %*d",
&act->mtime, &act->atime) == 2) {
act->settime = 1;
back->send(backhandle, "", 1);

View File

@ -4327,7 +4327,7 @@ static void term_out(Terminal *term)
for (i = 1; i < term->esc_nargs; i++) {
if (i != 1)
strcat(term->id_string, ";");
sprintf(lbuf, "%d", term->esc_args[i]);
sprintf(lbuf, "%u", term->esc_args[i]);
strcat(term->id_string, lbuf);
}
strcat(term->id_string, "c");

View File

@ -5199,8 +5199,8 @@ void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_des
multilen = WideCharToMultiByte(CP_ACP, 0, unitab+uindex, 1,
NULL, 0, NULL, NULL);
if (multilen != 1) {
blen = sprintf(before, "{\\uc%d\\u%d", multilen,
udata[uindex]);
blen = sprintf(before, "{\\uc%d\\u%d", (int)multilen,
(int)udata[uindex]);
alen = 1; strcpy(after, "}");
} else {
blen = sprintf(before, "\\u%d", udata[uindex]);