Dominique Pelle wrote:

> 1/ According to ":help functions", function cursor() is meant
> to return a value of type 'Number'.  But function cursor()
> (f_cursor() in eval.c) does not return anything.  So doing
> ":echo cursor(1,1)" prints an uninitialized value and valgrind
> reports the following error:
> 
> ==20458== Use of uninitialised value of size 4
> ==20458==    at 0x4F9A7F6: (within /lib/tls/i686/cmov/libc-2.8.90.so)
> ==20458==    by 0x4F9E398: vfprintf (in /lib/tls/i686/cmov/libc-2.8.90.so)
> ==20458==    by 0x4FBE02B: vsprintf (in /lib/tls/i686/cmov/libc-2.8.90.so)
> ==20458==    by 0x4FA5D3A: sprintf (in /lib/tls/i686/cmov/libc-2.8.90.so)
> ==20458==    by 0x80932DE: get_tv_string_buf_chk (stdio2.h:34)
> ==20458==    by 0x809334A: get_tv_string_buf (eval.c:18752)
> ==20458==    by 0x8094A71: echo_string (eval.c:7290)
> ==20458==    by 0x80AD37E: ex_echo (eval.c:19507)
> ==20458==    by 0x80CCA86: do_one_cmd (ex_docmd.c:2622)
> ==20458==    by 0x80CAD92: do_cmdline (ex_docmd.c:1096)
> ==20458==    by 0x8142E0F: nv_colon (normal.c:5218)
> ==20458==    by 0x8144EAF: normal_cmd (normal.c:1189)
> ==20458==    by 0x81044D6: main_loop (main.c:1180)
> ==20458==    by 0x81078B2: main (main.c:939)
> 
> Attached patch makes cursor() return 0 if success, -1 if failure.

Makes sense.

For a long time I've been wondering if we should set the default return
value to a zero number.  Currently the type is set to VAR_NUMBER, but
the value isn't set.

Looking over the functions, I can delete more than a dozen lines by
setting the default return value to zero.  And then we won't ever have
the problem of forgetting to set the value.  So let's do that.

> 2/ Function setpos() returns 'none' according to ":help functions"
> but looking at the code, it actually returns 0 in case of success
> and -1 in case of error.
> 
> Patch fixes documentation.

Good.

> 3/ Function complete() returns a String according to ":help functions"
> but it may return something initialized in case of error.
> :echo complete('', '') for example prints something uninitialized
> and valgrind also reports an error.
> 
> Patch makes it return an empty string in case of error.

I don't think it returns anything useful, might as well be the default
zero.

> 4/ Function feedkeys() always returns 0 according to ":help feedkeys()"
> but it may return something uninitialized when doing:
> 
> ":sandbox echo feedkeys('')
> 
> Attached patch makes it always return 0 as stated in documentation.

Also solved by the default return value.

> 5/ The following functions do not return anything:
> 
>     clearmatches()
>     garbagecollect()
>     winrestview()
> 
> So doing ":echo garbagecollect()" prints something uninitialized
> and valgrind reports uninitialized memory access.
> 
> Making them return something is better I think. So
> ":echo garbagecollect()" prints something deterministic.
> Attached patch makes them always return 0, just like what
> is already done for "feedkeys()".

Default return value takes care of this now.

-- 
hundred-and-one symptoms of being an internet addict:
254. You wake up daily with your keyboard printed on your forehead.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui