Hi
I have installed the clang static analyser on Linux
(http://clang-analyzer.llvm.org).
I've used it analyse the source code of Vim-7.2.330.
It finds several warnings.
Attached patch fixes some of them:
buffer.c:318:10: warning: Value stored to 'nwindows' during its
initialization is never read
int nwindows = buf->b_nwindows;
^ ~~~~~~~~~~~~~~~
edit.c:5831:6: warning: Value stored to 'textwidth' is never read
textwidth = 0;
^ ~
ex_getln.c:2196:2: warning: Value stored to 'pend' is never read
pend = (char_u *)line_ga.ga_data + line_ga.ga_len;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fileio.c:7094:3: warning: Value stored to 'itmplen' is never read
itmplen = STRLEN(itmp);
^ ~~~~~~~~~~~~
if_cscope.c:2072:7: warning: Although the value stored to 'fname' is
used in the enclosing expression, the value is never actually read
from 'fname'
if ((fname = strtok(tbuf, (const char *)"\t")) == NULL)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ops.c:5594:14: warning: Value stored to 'conv_str' during its
initialization is never read
char_u *conv_str = str;
^ ~~~
quickfix.c:1947:3: warning: Value stored to 'need_return' is never read
need_return = FALSE;
^ ~~~~~
syntax.c:4170:6: warning: Value stored to 'kp' is never read
kp = HI2KE(hi);
^ ~~~~~~~~~
ui.c:2386:14: warning: Value stored to 'conv_buf' during its
initialization is never read
char_u *conv_buf = buffer;
^ ~~~~~~
netbeans.c:1177:6: warning: Value stored to 'q' is never read
*q++ = '\0';
^~~
There are more warnings (which I have not fixed yet) at:
http://dominique.pelle.free.fr/clang-static-analysis-vim-7.2.330.txt
Cheers
-- Dominique
--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
diff -r 277085346a0d src/buffer.c
--- a/src/buffer.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/buffer.c Sun Jan 17 20:11:47 2010 +0100
@@ -315,7 +315,7 @@
{
#ifdef FEAT_AUTOCMD
int is_curbuf;
- int nwindows = buf->b_nwindows;
+ int nwindows;
#endif
int unload_buf = (action != 0);
int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
diff -r 277085346a0d src/edit.c
--- a/src/edit.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/edit.c Sun Jan 17 20:11:47 2010 +0100
@@ -4048,7 +4048,7 @@
save_p_ic = p_ic;
p_ic = ignorecase(compl_pattern);
- /* Find up to TAG_MANY matches. Avoids that an enourmous number
+ /* Find up to TAG_MANY matches. Avoids that an enormous number
* of matches is found when compl_pattern is empty */
if (find_tags(compl_pattern, &num_matches, &matches,
TAG_REGEXP | TAG_NAMES | TAG_NOIC |
@@ -4219,7 +4219,7 @@
|| IObuff[len - 2] == '!'))))
IObuff[len++] = ' ';
}
- /* copy as much as posible of the new word */
+ /* copy as much as possible of the new word */
if (tmp_ptr - ptr >= IOSIZE - len)
tmp_ptr = ptr + IOSIZE - len - 1;
STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
@@ -5828,7 +5828,6 @@
&& !has_format_option(FO_WRAP))
{
- textwidth = 0;
break;
}
if ((startcol = curwin->w_cursor.col) == 0)
diff -r 277085346a0d src/ex_getln.c
--- a/src/ex_getln.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/ex_getln.c Sun Jan 17 20:11:47 2010 +0100
@@ -2193,7 +2193,6 @@
{
if (ga_grow(&line_ga, 40) == FAIL)
break;
- pend = (char_u *)line_ga.ga_data + line_ga.ga_len;
/* Get one character at a time. Don't use inchar(), it can't handle
* special characters. */
@@ -3314,7 +3313,7 @@
WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
|options, type);
vim_free(p1);
- /* longest match: make sure it is not shorter (happens with :help */
+ /* longest match: make sure it is not shorter, happens with :help */
if (p2 != NULL && type == WILD_LONGEST)
{
for (j = 0; j < xp->xp_pattern_len; ++j)
diff -r 277085346a0d src/fileio.c
--- a/src/fileio.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/fileio.c Sun Jan 17 20:11:47 2010 +0100
@@ -7072,10 +7072,11 @@
*/
for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i)
{
- size_t itmplen;
# ifndef HAVE_MKDTEMP
long nr;
long off;
+# else
+ size_t itmplen;
# endif
/* expand $TMP, leave room for "/v1100000/999999999" */
@@ -7091,7 +7092,6 @@
else
# endif
add_pathsep(itmp);
- itmplen = STRLEN(itmp);
# ifdef HAVE_MKDTEMP
/* Leave room for filename */
@@ -7104,6 +7104,7 @@
* otherwise it doesn't matter. The use of mkdir() avoids any
* security problems because of the predictable number. */
nr = (mch_get_pid() + (long)time(NULL)) % 1000000L;
+ itmplen = STRLEN(itmp);
/* Try up to 10000 different values until we find a name that
* doesn't exist. */
diff -r 277085346a0d src/if_cscope.c
--- a/src/if_cscope.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/if_cscope.c Sun Jan 17 20:11:47 2010 +0100
@@ -2069,7 +2069,7 @@
continue;
(void)strcpy(tbuf, matches[idx]);
- if ((fname = strtok(tbuf, (const char *)"\t")) == NULL)
+ if (strtok(tbuf, (const char *)"\t") == NULL)
continue;
if ((fname = strtok(NULL, (const char *)"\t")) == NULL)
continue;
diff -r 277085346a0d src/netbeans.c
--- a/src/netbeans.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/netbeans.c Sun Jan 17 20:11:47 2010 +0100
@@ -873,7 +873,7 @@
{
#ifdef NBDEBUG
/*
- * This happens because the ExtEd can send a cammand or 2 after
+ * This happens because the ExtEd can send a command or 2 after
* doing a stopDocumentListen command. It doesn't harm anything
* so I'm disabling it except for debugging.
*/
@@ -1174,7 +1174,7 @@
break;
}
}
- *q++ = '\0';
+ *q = '\0';
return buf;
}
@@ -3070,7 +3070,7 @@
}
/*
- * Send netbeans an unmodufied command.
+ * Send netbeans an unmodified command.
*/
void
netbeans_unmodified(buf_T *bufp UNUSED)
@@ -3366,7 +3366,7 @@
/*
- * Add a sign of the reqested type at the requested location.
+ * Add a sign of the requested type at the requested location.
*
* Reverse engineering:
* Apparently an annotation is defined the first time it is used in a buffer.
diff -r 277085346a0d src/ops.c
--- a/src/ops.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/ops.c Sun Jan 17 20:11:47 2010 +0100
@@ -5591,13 +5591,13 @@
*/
if (has_mbyte)
{
- char_u *conv_str = str;
vimconv_T vc;
vc.vc_type = CONV_NONE;
if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
{
- int intlen = len;
+ int intlen = len;
+ char_u *conv_str;
conv_str = string_convert(&vc, str, &intlen);
len = intlen;
diff -r 277085346a0d src/quickfix.c
--- a/src/quickfix.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/quickfix.c Sun Jan 17 20:11:47 2010 +0100
@@ -1899,7 +1899,6 @@
int i;
int idx1 = 1;
int idx2 = -1;
- int need_return = TRUE;
char_u *arg = eap->arg;
int all = eap->forceit; /* if not :cl!, only show
recognised errors */
@@ -1939,13 +1938,9 @@
{
if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2)
{
- if (need_return)
- {
- msg_putchar('\n');
- if (got_int)
- break;
- need_return = FALSE;
- }
+ msg_putchar('\n');
+ if (got_int)
+ break;
fname = NULL;
if (qfp->qf_fnum != 0
@@ -1988,7 +1983,6 @@
IObuff, IOSIZE);
msg_prt_line(IObuff, FALSE);
out_flush(); /* show one line at a time */
- need_return = TRUE;
}
qfp = qfp->qf_next;
diff -r 277085346a0d src/syntax.c
--- a/src/syntax.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/syntax.c Sun Jan 17 20:11:47 2010 +0100
@@ -4167,7 +4167,6 @@
if (!HASHITEM_EMPTY(hi))
{
--todo;
- kp = HI2KE(hi);
for (kp = HI2KE(hi); kp != NULL; kp = kp_next)
{
kp_next = kp->ke_next;
diff -r 277085346a0d src/ui.c
--- a/src/ui.c Sat Jan 16 14:29:14 2010 +0100
+++ b/src/ui.c Sun Jan 17 20:11:47 2010 +0100
@@ -2383,13 +2383,13 @@
* 'enc' anyway. */
if (has_mbyte)
{
- char_u *conv_buf = buffer;
vimconv_T vc;
vc.vc_type = CONV_NONE;
if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK)
{
- conv_buf = string_convert(&vc, buffer, &nbytes);
+ char_u *conv_buf = string_convert(&vc, buffer, &nbytes);
+
if (conv_buf != NULL)
{
clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);