Mercurial > vim
changeset 11653:67cf0d45b006 v8.0.0709
patch 8.0.0709: libvterm cannot use vsnprintf()
commit https://github.com/vim/vim/commit/8327d1df1754b33d8a93b3411f30692f0042f4ce
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 11 22:34:51 2017 +0200
patch 8.0.0709: libvterm cannot use vsnprintf()
Problem: Libvterm cannot use vsnprintf(), it does not exist in C90.
Solution: Use vim_vsnprintf() instead.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 11 Jul 2017 22:45:03 +0200 |
parents | 8263fcf185e3 |
children | f555f26d134e |
files | src/Makefile src/evalfunc.c src/libvterm/src/vterm.c src/message.c src/netbeans.c src/proto.h src/version.c |
diffstat | 7 files changed, 51 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -8043,14 +8043,15 @@ f_printf(typval_T *argvars, typval_T *re /* 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;
--- 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 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, ...)
--- 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 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, ch 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) {
--- 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));
--- a/src/proto.h +++ b/src/proto.h @@ -127,7 +127,8 @@ int # 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"