From 81a520e60edf7b87843dea1e9d9dabfb6f0d8ca8 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 26 Feb 2018 14:24:45 +0100 Subject: [PATCH 1/2] vim-patch:8.0.1439: if cscope fails a search Vim may hang Problem: If cscope fails a search Vim may hang. Solution: Bail out when a search error is encountered. (Safouane Baroudi, closes vim/vim#2598) https://github.com/vim/vim/commit/1274d33493efb6250470a37b9f4432bb31e87d64 --- src/nvim/if_cscope.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 773e29693c..5bd1fdfcfb 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -549,7 +549,7 @@ static void cs_reading_emsg( static int cs_cnt_matches(size_t idx) { char *stok; - int nlines; + int nlines = 0; char *buf = xmalloc(CSREAD_BUFSIZE); for (;; ) { @@ -569,16 +569,20 @@ static int cs_cnt_matches(size_t idx) return CSCOPE_FAILURE; } - /* - * If the database is out of date, or there's some other problem, - * cscope will output error messages before the number-of-lines output. - * Display/discard any output that doesn't match what we want. - * Accept "\S*cscope: X lines", also matches "mlcscope". - */ - if ((stok = strtok(buf, (const char *)" ")) == NULL) + // If the database is out of date, or there's some other problem, + // cscope will output error messages before the number-of-lines output. + // Display/discard any output that doesn't match what we want. + // Accept "\S*cscope: X lines", also matches "mlcscope". + // Bail out for the "Unable to search" error. + if (strstr((const char *)stok, "Unable to search database") != NULL) { + break; + } + if ((stok = strtok(buf, (const char *)" ")) == NULL) { continue; - if (strstr((const char *)stok, "cscope:") == NULL) + } + if (strstr((const char *)stok, "cscope:") == NULL) { continue; + } if ((stok = strtok(NULL, (const char *)" ")) == NULL) continue; From e237cff0c8a2d77289983c39aa914bba76f25663 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 26 Feb 2018 14:40:44 +0100 Subject: [PATCH 2/2] vim-patch:8.0.1442: using pointer before it is set Problem: Using pointer before it is set. Solution: Search in whole buffer instead of next token. https://github.com/vim/vim/commit/a172b63ab8661019dba61285a738c8b6b55a33aa --- src/nvim/if_cscope.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 5bd1fdfcfb..5c3dfb0caf 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -574,7 +574,7 @@ static int cs_cnt_matches(size_t idx) // Display/discard any output that doesn't match what we want. // Accept "\S*cscope: X lines", also matches "mlcscope". // Bail out for the "Unable to search" error. - if (strstr((const char *)stok, "Unable to search database") != NULL) { + if (strstr((const char *)buf, "Unable to search database") != NULL) { break; } if ((stok = strtok(buf, (const char *)" ")) == NULL) {