When a tag is not found, cscope return the string "Unable to search database."
but the cs_cnt_matches() does not handle this case.
cs_cnt_matches():
When cscope does not find a tag, it returns "Unable to search
database", and thus:
if (strstr((const char *)stok, "cscope:") == NULL)
continue;
becomes:
if (strstr((const char *)stok, "cscope:") == NULL)
break;
and return nlines which must be initialized at zero.
Continuing does not make sens, and result in a buffer underflow on my
machine when the loop calls fgets for the second time.
cscope version: 15.8b
vim version: v8.0.1437 (cloned from git)
uname -r: 4.9.65
below is attached my git patch.
This is my first public patch ever in any project so I am new to this kind of
thing and I am a total newbie, I am waiting for your remarks.
--
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
>From 1f6c60dc10dd8573c5d3175b275b42383d41cc3f Mon Sep 17 00:00:00 2001
From: Safouane BAROUDI <[email protected]>
Date: Mon, 29 Jan 2018 02:15:12 +0100
Subject: [PATCH] cscope: vim hangs when a tag is not found
cs_cnt_matches():
When cscope does not find a tag, it returns "Unable to search
database", and thus:
if (strstr((const char *)stok, "cscope:") == NULL)
continue;
becomes:
if (strstr((const char *)stok, "cscope:") == NULL)
break;
and return nlines which must be initialized at zero.
Continuing does not make sens, and result in a buffer underflow on my
machine when the loop calls fgets for the second time.
---
src/if_cscope.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/if_cscope.c b/src/if_cscope.c
index 168b3e49e..4dba2961e 100644
--- a/src/if_cscope.c
+++ b/src/if_cscope.c
@@ -677,7 +677,7 @@ cs_cnt_matches(int idx)
{
char *stok;
char *buf;
- int nlines;
+ int nlines=0;
buf = (char *)alloc(CSREAD_BUFSIZE);
if (buf == NULL)
@@ -704,7 +704,7 @@ cs_cnt_matches(int idx)
if ((stok = strtok(buf, (const char *)" ")) == NULL)
continue;
if (strstr((const char *)stok, "cscope:") == NULL)
- continue;
+ break;
if ((stok = strtok(NULL, (const char *)" ")) == NULL)
continue;
--
2.11.0