Use portable format specifiers: Case %ld - plain - sprintf.

Fix uses of plain "%ld" within sprintf():
- Replace "%ld" with "%" PRId64.
- Cast corresponding argument to (int64_t).
This commit is contained in:
Eliseo Martínez
2014-04-19 12:28:26 +02:00
committed by Thiago de Arruda
parent f916cf067d
commit fb94edf373
12 changed files with 34 additions and 32 deletions

View File

@@ -1984,7 +1984,7 @@ static void list_buf_vars(int *first)
list_hashtable_vars(&curbuf->b_vars->dv_hashtab, (char_u *)"b:", list_hashtable_vars(&curbuf->b_vars->dv_hashtab, (char_u *)"b:",
TRUE, first); TRUE, first);
sprintf((char *)numbuf, "%ld", (long)curbuf->b_changedtick); sprintf((char *)numbuf, "%" PRId64, (int64_t)curbuf->b_changedtick);
list_one_var_a((char_u *)"b:", (char_u *)"changedtick", VAR_NUMBER, list_one_var_a((char_u *)"b:", (char_u *)"changedtick", VAR_NUMBER,
numbuf, first); numbuf, first);
} }
@@ -7320,7 +7320,7 @@ call_func (
if (current_SID <= 0) if (current_SID <= 0)
error = ERROR_SCRIPT; error = ERROR_SCRIPT;
else { else {
sprintf((char *)fname_buf + 3, "%ld_", (long)current_SID); sprintf((char *)fname_buf + 3, "%" PRId64 "_", (int64_t)current_SID);
i = (int)STRLEN(fname_buf); i = (int)STRLEN(fname_buf);
} }
} }
@@ -9360,7 +9360,7 @@ static void f_function(typval_T *argvars, typval_T *rettv)
* also be called from another script. Using trans_function_name() * also be called from another script. Using trans_function_name()
* would also work, but some plugins depend on the name being * would also work, but some plugins depend on the name being
* printable text. */ * printable text. */
sprintf(sid_buf, "<SNR>%ld_", (long)current_SID); sprintf(sid_buf, "<SNR>%" PRId64 "_", (int64_t)current_SID);
rettv->vval.v_string = rettv->vval.v_string =
alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1)); alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1));
if (rettv->vval.v_string != NULL) { if (rettv->vval.v_string != NULL) {
@@ -9992,7 +9992,7 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
case MCHAR: buf[0] = 'v'; break; case MCHAR: buf[0] = 'v'; break;
case MBLOCK: case MBLOCK:
buf[0] = Ctrl_V; buf[0] = Ctrl_V;
sprintf((char *)buf + 1, "%ld", reglen + 1); sprintf((char *)buf + 1, "%" PRId64, (int64_t)reglen + 1);
break; break;
} }
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@@ -16431,7 +16431,7 @@ static char_u *get_tv_string_buf_chk(typval_T *varp, char_u *buf)
{ {
switch (varp->v_type) { switch (varp->v_type) {
case VAR_NUMBER: case VAR_NUMBER:
sprintf((char *)buf, "%ld", (long)varp->vval.v_number); sprintf((char *)buf, "%" PRId64, (int64_t)varp->vval.v_number);
return buf; return buf;
case VAR_FUNC: case VAR_FUNC:
EMSG(_("E729: using Funcref as a String")); EMSG(_("E729: using Funcref as a String"));
@@ -17998,7 +17998,7 @@ trans_function_name (
EMSG(_(e_usingsid)); EMSG(_(e_usingsid));
goto theend; goto theend;
} }
sprintf((char *)sid_buf, "%ld_", (long)current_SID); sprintf((char *)sid_buf, "%" PRId64 "_", (int64_t)current_SID);
lead += (int)STRLEN(sid_buf); lead += (int)STRLEN(sid_buf);
} }
} else if (!(flags & TFN_INT) && builtin_function(lv.ll_name)) { } else if (!(flags & TFN_INT) && builtin_function(lv.ll_name)) {

View File

@@ -6112,7 +6112,8 @@ void ex_sign(exarg_T *eap)
cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25);
if (cmd == NULL) if (cmd == NULL)
return; return;
sprintf((char *)cmd, "e +%ld %s", (long)lnum, buf->b_fname); sprintf((char *)cmd, "e +%" PRId64 " %s",
(int64_t)lnum, buf->b_fname);
do_cmdline_cmd(cmd); do_cmdline_cmd(cmd);
vim_free(cmd); vim_free(cmd);
} }

View File

@@ -4493,13 +4493,13 @@ static void uc_list(char_u *name, size_t name_len)
if (a & (RANGE|COUNT)) { if (a & (RANGE|COUNT)) {
if (a & COUNT) { if (a & COUNT) {
/* -count=N */ /* -count=N */
sprintf((char *)IObuff + len, "%ldc", cmd->uc_def); sprintf((char *)IObuff + len, "%" PRId64 "c", (int64_t)cmd->uc_def);
len += (int)STRLEN(IObuff + len); len += (int)STRLEN(IObuff + len);
} else if (a & DFLALL) } else if (a & DFLALL)
IObuff[len++] = '%'; IObuff[len++] = '%';
else if (cmd->uc_def >= 0) { else if (cmd->uc_def >= 0) {
/* -range=N */ /* -range=N */
sprintf((char *)IObuff + len, "%ld", cmd->uc_def); sprintf((char *)IObuff + len, "%" PRId64 "", (int64_t)cmd->uc_def);
len += (int)STRLEN(IObuff + len); len += (int)STRLEN(IObuff + len);
} else } else
IObuff[len++] = '.'; IObuff[len++] = '.';
@@ -4999,7 +4999,7 @@ uc_check_code (
(eap->addr_count > 0) ? eap->line2 : cmd->uc_def; (eap->addr_count > 0) ? eap->line2 : cmd->uc_def;
size_t num_len; size_t num_len;
sprintf(num_buf, "%ld", num); sprintf(num_buf, "%" PRId64, (int64_t)num);
num_len = STRLEN(num_buf); num_len = STRLEN(num_buf);
result = num_len; result = num_len;
@@ -8003,7 +8003,7 @@ eval_vars (
*errormsg = (char_u *)_("E842: no line number to use for \"<slnum>\""); *errormsg = (char_u *)_("E842: no line number to use for \"<slnum>\"");
return NULL; return NULL;
} }
sprintf((char *)strbuf, "%ld", (long)sourcing_lnum); sprintf((char *)strbuf, "%" PRId64, (int64_t)sourcing_lnum);
result = strbuf; result = strbuf;
break; break;
} }

View File

@@ -4147,7 +4147,8 @@ void msg_add_lines(int insert_space, long lnum, off_t nchars)
if (insert_space) if (insert_space)
*p++ = ' '; *p++ = ' ';
if (shortmess(SHM_LINES)) { if (shortmess(SHM_LINES)) {
sprintf((char *)p, "%ldL, %" PRId64 "C", lnum, (int64_t)nchars); sprintf((char *)p, "%" PRId64 "L, %" PRId64 "C",
(int64_t)lnum, (int64_t)nchars);
} }
else { else {
if (lnum == 1) if (lnum == 1)
@@ -5696,7 +5697,7 @@ vim_tempname (
mode_t umask_save; mode_t umask_save;
# endif # endif
sprintf((char *)itmp + itmplen, "v%ld", nr + off); sprintf((char *)itmp + itmplen, "v%" PRId64, (int64_t)nr + off);
# ifndef EEXIST # ifndef EEXIST
/* If mkdir() does not set errno to EEXIST, check for /* If mkdir() does not set errno to EEXIST, check for
* existing file here. There is a race condition then, * existing file here. There is a race condition then,
@@ -5735,7 +5736,7 @@ vim_tempname (
if (vim_tempdir != NULL) { if (vim_tempdir != NULL) {
/* There is no need to check if the file exists, because we own the /* There is no need to check if the file exists, because we own the
* directory and nobody else creates a file in it. */ * directory and nobody else creates a file in it. */
sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++); sprintf((char *)itmp, "%s%" PRId64, vim_tempdir, (int64_t)temp_count++);
return vim_strsave(itmp); return vim_strsave(itmp);
} }

View File

@@ -308,7 +308,7 @@ static void add_num_buff(buffheader_T *buf, long n)
{ {
char_u number[32]; char_u number[32];
sprintf((char *)number, "%ld", n); sprintf((char *)number, "%" PRId64, (int64_t)n);
add_buff(buf, number, -1L); add_buff(buf, number, -1L);
} }

View File

@@ -1064,7 +1064,7 @@ void msg_outnum(long n)
{ {
char_u buf[20]; char_u buf[20];
sprintf((char *)buf, "%ld", n); sprintf((char *)buf, "%" PRId64, (int64_t)n);
msg_puts(buf); msg_puts(buf);
} }

View File

@@ -3024,10 +3024,10 @@ void clear_showcmd(void)
p_sbr = empty_option; p_sbr = empty_option;
getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol);
p_sbr = saved_sbr; p_sbr = saved_sbr;
sprintf((char *)showcmd_buf, "%ldx%ld", lines, sprintf((char *)showcmd_buf, "%" PRId64 "x%" PRId64,
(long)(rightcol - leftcol + 1)); (int64_t)lines, (int64_t)(rightcol - leftcol + 1));
} else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) } else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum)
sprintf((char *)showcmd_buf, "%ld", lines); sprintf((char *)showcmd_buf, "%" PRId64, (int64_t)lines);
else { else {
char_u *s, *e; char_u *s, *e;
int l; int l;
@@ -4451,7 +4451,7 @@ static void nv_ident(cmdarg_T *cap)
isman = (STRCMP(kp, "man") == 0); isman = (STRCMP(kp, "man") == 0);
isman_s = (STRCMP(kp, "man -s") == 0); isman_s = (STRCMP(kp, "man -s") == 0);
if (cap->count0 != 0 && !(isman || isman_s)) if (cap->count0 != 0 && !(isman || isman_s))
sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); sprintf((char *)buf, ".,.+%" PRId64, (int64_t)cap->count0 - 1);
STRCAT(buf, "! "); STRCAT(buf, "! ");
if (cap->count0 == 0 && isman_s) if (cap->count0 == 0 && isman_s)
@@ -4460,7 +4460,7 @@ static void nv_ident(cmdarg_T *cap)
STRCAT(buf, kp); STRCAT(buf, kp);
STRCAT(buf, " "); STRCAT(buf, " ");
if (cap->count0 != 0 && (isman || isman_s)) { if (cap->count0 != 0 && (isman || isman_s)) {
sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); sprintf((char *)buf + STRLEN(buf), "%" PRId64, (int64_t)cap->count0);
STRCAT(buf, " "); STRCAT(buf, " ");
} }
} }
@@ -4482,7 +4482,7 @@ static void nv_ident(cmdarg_T *cap)
if (g_cmd) if (g_cmd)
STRCPY(buf, "tj "); STRCPY(buf, "tj ");
else else
sprintf((char *)buf, "%ldta ", cap->count0); sprintf((char *)buf, "%" PRId64 "ta ", (int64_t)cap->count0);
} }
} }

View File

@@ -7535,7 +7535,7 @@ option_value2string (
else if (wc != 0) else if (wc != 0)
STRCPY(NameBuff, transchar((int)wc)); STRCPY(NameBuff, transchar((int)wc));
else else
sprintf((char *)NameBuff, "%ld", *(long *)varp); sprintf((char *)NameBuff, "%" PRId64, (int64_t)*(long *)varp);
} else { /* P_STRING */ } else { /* P_STRING */
varp = *(char_u **)(varp); varp = *(char_u **)(varp);
if (varp == NULL) /* just in case */ if (varp == NULL) /* just in case */

View File

@@ -1802,10 +1802,10 @@ void qf_list(exarg_T *eap)
if (qfp->qf_lnum == 0) if (qfp->qf_lnum == 0)
IObuff[0] = NUL; IObuff[0] = NUL;
else if (qfp->qf_col == 0) else if (qfp->qf_col == 0)
sprintf((char *)IObuff, ":%ld", qfp->qf_lnum); sprintf((char *)IObuff, ":%" PRId64, (int64_t)qfp->qf_lnum);
else else
sprintf((char *)IObuff, ":%ld col %d", sprintf((char *)IObuff, ":%" PRId64 " col %d",
qfp->qf_lnum, qfp->qf_col); (int64_t)qfp->qf_lnum, qfp->qf_col);
sprintf((char *)IObuff + STRLEN(IObuff), "%s:", sprintf((char *)IObuff + STRLEN(IObuff), "%s:",
(char *)qf_types(qfp->qf_type, qfp->qf_nr)); (char *)qf_types(qfp->qf_type, qfp->qf_nr));
msg_puts_attr(IObuff, hl_attr(HLF_N)); msg_puts_attr(IObuff, hl_attr(HLF_N));
@@ -2357,7 +2357,7 @@ static void qf_fill_buffer(qf_info_T *qi)
IObuff[len++] = '|'; IObuff[len++] = '|';
if (qfp->qf_lnum > 0) { if (qfp->qf_lnum > 0) {
sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum); sprintf((char *)IObuff + len, "%" PRId64, (int64_t)qfp->qf_lnum);
len += (int)STRLEN(IObuff + len); len += (int)STRLEN(IObuff + len);
if (qfp->qf_col > 0) { if (qfp->qf_col > 0) {

View File

@@ -1074,7 +1074,7 @@ proftime_T *tm; /* timeout limit or NULL */
if (spats[0].off.off > 0 || spats[0].off.line) if (spats[0].off.off > 0 || spats[0].off.line)
*p++ = '+'; *p++ = '+';
if (spats[0].off.off != 0 || spats[0].off.line) if (spats[0].off.off != 0 || spats[0].off.line)
sprintf((char *)p, "%ld", spats[0].off.off); sprintf((char *)p, "%" PRId64, (int64_t)spats[0].off.off);
else else
*p = NUL; *p = NUL;
} }

View File

@@ -4249,7 +4249,7 @@ replace_termcodes (
result[dlen++] = K_SPECIAL; result[dlen++] = K_SPECIAL;
result[dlen++] = (int)KS_EXTRA; result[dlen++] = (int)KS_EXTRA;
result[dlen++] = (int)KE_SNR; result[dlen++] = (int)KE_SNR;
sprintf((char *)result + dlen, "%ld", (long)current_SID); sprintf((char *)result + dlen, "%" PRId64, (int64_t)current_SID);
dlen += (int)STRLEN(result + dlen); dlen += (int)STRLEN(result + dlen);
result[dlen++] = '_'; result[dlen++] = '_';
continue; continue;

View File

@@ -470,8 +470,8 @@ wingotofile:
* cursor in a new window. * cursor in a new window.
*/ */
if (bt_quickfix(curbuf)) { if (bt_quickfix(curbuf)) {
sprintf((char *)cbuf, "split +%ld%s", sprintf((char *)cbuf, "split +%" PRId64 "%s",
(long)curwin->w_cursor.lnum, (int64_t)curwin->w_cursor.lnum,
(curwin->w_llist_ref == NULL) ? "cc" : "ll"); (curwin->w_llist_ref == NULL) ? "cc" : "ll");
do_cmdline_cmd(cbuf); do_cmdline_cmd(cbuf);
} }