[patch] clean up a few warnings reported by cppcheck

2017-04-06 Fir de Conversatie Dominique Pellé
Hi

Attached patch cleans up a few warnings reported by cppcheck:

[vim/src/channel.c:2574]: (error) Common realloc mistake: 'buf' nulled
but not freed upon failure

[vim/src/edit.c:9527]: (warning) Char literal compared with pointer
'end'. Did you intend to dereference it?

[vim/src/farsi.c:1698]: (style) Array index 'i' is used before limits check.


Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/channel.c b/src/channel.c
index 410f928..106b711 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -2571,9 +2571,12 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
 	if (nl == NULL)
 	{
 		/* Flush remaining message that is missing a NL. */
-		buf = vim_realloc(buf, node->rq_buflen + 1);
-		if (buf == NULL)
+		char_u	*new_buf;
+
+		new_buf = vim_realloc(buf, node->rq_buflen + 1);
+		if (new_buf == NULL)
 		return FALSE;
+		buf = new_buf;
 		node->rq_buffer = buf;
 		nl = buf + node->rq_buflen++;
 		*nl = NUL;
diff --git a/src/edit.c b/src/edit.c
index ad8b89a..0153f3b 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -9524,7 +9524,7 @@ bracketed_paste(paste_mode_T mode, int drop, garray_T *gap)
 #endif
 	buf[idx++] = c;
 	buf[idx] = NUL;
-	if (end != NUL && STRNCMP(buf, end, idx) == 0)
+	if (end != NULL && STRNCMP(buf, end, idx) == 0)
 	{
 	if (end[idx] == NUL)
 		break; /* Found the end of paste code. */
diff --git a/src/farsi.c b/src/farsi.c
index bac1510..ebed47e 100644
--- a/src/farsi.c
+++ b/src/farsi.c
@@ -1695,7 +1695,7 @@ conv_to_pvim(void)
 		ptr[i] = toF_leading(ptr[i]);
 		++i;
 
-		while (canF_Rjoin(ptr[i]) && i < llen)
+		while (i < llen && canF_Rjoin(ptr[i]))
 		{
 		ptr[i] = toF_Rjoin(ptr[i]);
 		if (F_isterm(ptr[i]) || !F_isalpha(ptr[i]))


Re: Inconsistency between the different insert mode * commands

2017-04-06 Fir de Conversatie Ramel Eshed
On Wednesday, April 5, 2017 at 9:47:21 PM UTC+3, Bram Moolenaar wrote:
> Ramel Eshed wrote:
> 
> > > > vim -u NONE
> > > > 
> > > > ia="b\n"
> > > > 
> > > > results:
> > > > ab
> > > > 
> > > > 
> > > > This should be the expected behavior as I understand. But if I use 
> > > > instead:
> > > > ia="b\n"
> > > > 
> > > > I get:
> > > > b
> > > > a
> > > > 
> > > > Also:
> > > > 
> > > > ia="b\n"
> > > > I get:
> > > > ab^@
> > > > 
> > > > -the ^@ is displayed instead of an empty new line.
> > > > 
> > > > I'm using vim 8.0.540 on RHEL6. Please look into it.
> > > 
> > > Vim offers those different commands to be able to insert different
> > > things.  So it's normal that they work differently.
> > > 
> > > On top of that, it appears that in the second case the register is
> > > recognized as linewise, since the text ends in a NL.
> > > 
> > 
> > Hi Bram,
> > 
> > I'm aware to the differences between these commands. According to the 
> > documentation both  and  insert the text literally and 
> > the only difference is if the formatting options are used or not. I don't 
> > see how formatting is related to my example or why one command uses a 
> > linewise register while the other is not.
> > 
> > Also, I'm not sure if this is related, but I noticed that the results of 
> > the following two sequences are different:
> > 1) ia="b\n"
> > 2) let @b="b\n"
> >iab
> 
> Yes, the first one evaluates an expression and inserts the result.  The
> second one assigns an expression to a register, where the trailing NL
> causes it to become linewise.  An expression itself is just a string,
> a register can be linewise.

Ok, but still why  considers the above b register (let @b="b\n") 
linewise while  not?

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.