Skip to content

Commit

Permalink
imap-send: Fix sprintf usage
Browse files Browse the repository at this point in the history
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 <avarab@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ævar Arnfjörð Bjarmason authored and Junio C Hamano committed Aug 9, 2010
1 parent 24aea03 commit 1702b13
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,13 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
while (imap->literal_pending)
get_cmd_result(ctx, NULL);

bufl = nfsnprintf(buf, sizeof(buf), cmd->cb.data ? CAP(LITERALPLUS) ?
"%d %s{%d+}\r\n" : "%d %s{%d}\r\n" : "%d %s\r\n",
cmd->tag, cmd->cmd, cmd->cb.dlen);
if (!cmd->cb.data)
bufl = nfsnprintf(buf, sizeof(buf), "%d %s\r\n", cmd->tag, cmd->cmd);
else
bufl = nfsnprintf(buf, sizeof(buf), "%d %s{%d%s}\r\n",
cmd->tag, cmd->cmd, cmd->cb.dlen,
CAP(LITERALPLUS) ? "+" : "");

if (Verbose) {
if (imap->num_in_progress)
printf("(%d in progress) ", imap->num_in_progress);
Expand Down Expand Up @@ -1086,7 +1090,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
int gai;
char portstr[6];

snprintf(portstr, sizeof(portstr), "%hu", srvc->port);
snprintf(portstr, sizeof(portstr), "%d", srvc->port);

memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
Expand Down

0 comments on commit 1702b13

Please sign in to comment.