Permalink
Browse files

patch 8.0.0709: libvterm cannot use vsnprintf()

Problem:    Libvterm cannot use vsnprintf(), it does not exist in C90.
Solution:   Use vim_vsnprintf() instead.
  • Loading branch information...
brammool committed Jul 11, 2017
1 parent 292eff0 commit 8327d1df1754b33d8a93b3411f30692f0042f4ce
Showing with 51 additions and 10 deletions.
  1. +1 −1 src/Makefile
  2. +3 −2 src/evalfunc.c
  3. +27 −0 src/libvterm/src/vterm.c
  4. +15 −5 src/message.c
  5. +1 −1 src/netbeans.c
  6. +2 −1 src/proto.h
  7. +2 −0 src/version.c
View
@@ -3284,7 +3284,7 @@ objects/channel.o: channel.c
Makefile:
@echo The name of the makefile MUST be "Makefile" (with capital M)!!!!
CCCTERM = $(CCC) -Ilibvterm/include -DINLINE=""
CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf
objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS)
$(CCCTERM) -o $@ libvterm/src/encoding.c
View
@@ -8043,14 +8043,15 @@ f_printf(typval_T *argvars, typval_T *rettv)
/* Get the required length, allocate the buffer and do it for real. */
did_emsg = FALSE;
fmt = (char *)get_tv_string_buf(&argvars[0], buf);
len = vim_vsnprintf(NULL, 0, fmt, ap, argvars + 1);
len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1);
if (!did_emsg)
{
s = alloc(len + 1);
if (s != NULL)
{
rettv->vval.v_string = s;
(void)vim_vsnprintf((char *)s, len + 1, fmt, ap, argvars + 1);
(void)vim_vsnprintf_typval((char *)s, len + 1, fmt,
ap, argvars + 1);
}
}
did_emsg |= saved_did_emsg;
View
@@ -130,16 +130,42 @@ static int outbuffer_is_full(VTerm *vt)
return vt->outbuffer_cur >= vt->outbuffer_len - 1;
}
#if _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _BSD_SOURCE
# undef VSNPRINTF
# define VSNPRINTF vsnprintf
#else
# ifdef VSNPRINTF
/* Use a provided vsnprintf() function. */
int VSNPRINTF(char *str, size_t str_m, const char *fmt, va_list ap);
# endif
#endif
INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list args)
{
int written;
#ifndef VSNPRINTF
/* When vsnprintf() is not available (C90) fall back to vsprintf(). */
char buffer[1024]; /* 1Kbyte is enough for everybody, right? */
#endif
if(outbuffer_is_full(vt)) {
DEBUG_LOG("vterm_push_output(): buffer overflow; truncating output\n");
return;
}
#ifdef VSNPRINTF
written = VSNPRINTF(vt->outbuffer + vt->outbuffer_cur,
vt->outbuffer_len - vt->outbuffer_cur,
format, args);
if(written == (int)(vt->outbuffer_len - vt->outbuffer_cur)) {
/* output was truncated */
vt->outbuffer_cur = vt->outbuffer_len - 1;
}
else
vt->outbuffer_cur += written;
#else
written = vsprintf(buffer, format, args);
if(written >= (int)(vt->outbuffer_len - vt->outbuffer_cur)) {
@@ -151,6 +177,7 @@ INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list
strncpy(vt->outbuffer + vt->outbuffer_cur, buffer, written + 1);
vt->outbuffer_cur += written;
}
#endif
}
INTERNAL void vterm_push_output_sprintf(VTerm *vt, const char *format, ...)
View
@@ -382,7 +382,7 @@ smsg(char_u *s, ...)
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
va_end(arglist);
return msg(IObuff);
}
@@ -396,7 +396,7 @@ smsg_attr(int attr, char_u *s, ...)
va_list arglist;
va_start(arglist, s);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist, NULL);
vim_vsnprintf((char *)IObuff, IOSIZE, (char *)s, arglist);
va_end(arglist);
return msg_attr(IObuff, attr);
}
@@ -4232,7 +4232,7 @@ infinity_str(int positive,
/*
* When va_list is not supported we only define vim_snprintf().
*
* vim_vsnprintf() can be invoked with either "va_list" or a list of
* vim_vsnprintf_typval() can be invoked with either "va_list" or a list of
* "typval_T". When the latter is not used it must be NULL.
*/
@@ -4254,7 +4254,7 @@ vim_snprintf_add(char *str, size_t str_m, char *fmt, ...)
else
space = str_m - len;
va_start(ap, fmt);
str_l = vim_vsnprintf(str + len, space, fmt, ap, NULL);
str_l = vim_vsnprintf(str + len, space, fmt, ap);
va_end(ap);
return str_l;
}
@@ -4266,13 +4266,23 @@ vim_snprintf(char *str, size_t str_m, char *fmt, ...)
int str_l;
va_start(ap, fmt);
str_l = vim_vsnprintf(str, str_m, fmt, ap, NULL);
str_l = vim_vsnprintf(str, str_m, fmt, ap);
va_end(ap);
return str_l;
}
int
vim_vsnprintf(
char *str,
size_t str_m,
char *fmt,
va_list ap)
{
return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL);
}
int
vim_vsnprintf_typval(
char *str,
size_t str_m,
char *fmt,
View
@@ -2301,7 +2301,7 @@ coloncmd(char *cmd, ...)
va_list ap;
va_start(ap, cmd);
vim_vsnprintf(buf, sizeof(buf), cmd, ap, NULL);
vim_vsnprintf(buf, sizeof(buf), cmd, ap);
va_end(ap);
nbdebug((" COLONCMD %s\n", buf));
View
@@ -127,7 +127,8 @@ _RTLENTRYF
# endif
vim_snprintf(char *, size_t, char *, ...);
int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs);
int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap);
int vim_vsnprintf_typval(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs);
# include "message.pro"
# include "misc1.pro"
View
@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
709,
/**/
708,
/**/

0 comments on commit 8327d1d

Please sign in to comment.