diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-07-11 22:34:51 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-07-11 22:34:51 +0200 |
commit | 8327d1df1754b33d8a93b3411f30692f0042f4ce (patch) | |
tree | 6f2d59fd480125984eef99d22941edc37f23d31c | |
parent | 292eff0c5aacb8531d65509679b6c29eae8dc22a (diff) | |
download | vim-git-8327d1df1754b33d8a93b3411f30692f0042f4ce.tar.gz |
patch 8.0.0709: libvterm cannot use vsnprintf()v8.0.0709
Problem: Libvterm cannot use vsnprintf(), it does not exist in C90.
Solution: Use vim_vsnprintf() instead.
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/evalfunc.c | 5 | ||||
-rw-r--r-- | src/libvterm/src/vterm.c | 27 | ||||
-rw-r--r-- | src/message.c | 20 | ||||
-rw-r--r-- | src/netbeans.c | 2 | ||||
-rw-r--r-- | src/proto.h | 3 | ||||
-rw-r--r-- | src/version.c | 2 |
7 files changed, 51 insertions, 10 deletions
diff --git a/src/Makefile b/src/Makefile index 2071217d2..6c236ca71 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 diff --git a/src/evalfunc.c b/src/evalfunc.c index 3af5cd74b..75ebb20db 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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; diff --git a/src/libvterm/src/vterm.c b/src/libvterm/src/vterm.c index 8dca1b256..2931e5202 100644 --- a/src/libvterm/src/vterm.c +++ b/src/libvterm/src/vterm.c @@ -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, ...) diff --git a/src/message.c b/src/message.c index aeceee1b4..9320d118b 100644 --- a/src/message.c +++ b/src/message.c @@ -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,7 +4266,7 @@ 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; } @@ -4276,6 +4276,16 @@ 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, va_list ap, typval_T *tvs) { diff --git a/src/netbeans.c b/src/netbeans.c index fb4cb766d..93563b115 100644 --- a/src/netbeans.c +++ b/src/netbeans.c @@ -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)); diff --git a/src/proto.h b/src/proto.h index 729fea38a..b5a6224a9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -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" diff --git a/src/version.c b/src/version.c index b4e7d2e8c..e284648f2 100644 --- a/src/version.c +++ b/src/version.c @@ -765,6 +765,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 709, +/**/ 708, /**/ 707, |