Skip to content

Commit 1702b13

Browse files
avargitster
authored andcommitted
imap-send: Fix sprintf usage
When composing a command for the imap server, imap-send uses a single nfsnprintf() invocation for brevity instead of dealing separately with the case when there is a message to be sent and the case when there isn’t. The unused argument in the second case, while valid, is confusing for static analyzers and human readers. v1.6.4-rc0~117 (imap-send: add support for IPv6, 2009-05-25) mistakenly used %hu as the format for an int “port”, by analogy with existing usage for the unsigned short “addr.sin_port”.  Use %d instead. Noticed with clang. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24aea03 commit 1702b13

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

imap-send.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,13 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
543543
while (imap->literal_pending)
544544
get_cmd_result(ctx, NULL);
545545

546-
bufl = nfsnprintf(buf, sizeof(buf), cmd->cb.data ? CAP(LITERALPLUS) ?
547-
"%d %s{%d+}\r\n" : "%d %s{%d}\r\n" : "%d %s\r\n",
548-
cmd->tag, cmd->cmd, cmd->cb.dlen);
546+
if (!cmd->cb.data)
547+
bufl = nfsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd);
548+
else
549+
bufl = nfsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n",
550+
cmd->tag, cmd->cmd, cmd->cb.dlen,
551+
CAP(LITERALPLUS) ? "+" : "");
552+
549553
if (Verbose) {
550554
if (imap->num_in_progress)
551555
printf("(%d in progress) ", imap->num_in_progress);
@@ -1086,7 +1090,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
10861090
int gai;
10871091
char portstr[6];
10881092

1089-
snprintf(portstr, sizeof(portstr), "%hu", srvc->port);
1093+
snprintf(portstr, sizeof(portstr), "%d", srvc->port);
10901094

10911095
memset(&hints, 0, sizeof(hints));
10921096
hints.ai_socktype = SOCK_STREAM;

0 commit comments

Comments
 (0)