summaryrefslogtreecommitdiff
path: root/legacy/clucene/static-fixes.patch
blob: 8e80e81af9bb3d600029742d82620ca2726acf44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
From 6e04e9db12d0696dcd3dcc40ec61615fa5762592 Mon Sep 17 00:00:00 2001
From: Anton Bannikov <Anton.Bannikov@Kaspersky.com>
Date: Thu, 1 Sep 2022 16:48:07 +0300
Subject: [PATCH] [svace] fix errors found by svace static analyzer

---
 src/core/CLucene/debug/error.cpp           | 12 ++++++++++
 src/core/CLucene/debug/error.h             |  1 +
 src/core/CLucene/index/TermInfosReader.cpp | 28 ++++++++++++----------
 src/core/CLucene/search/MultiSearcher.cpp  | 24 ++++++++++++-------
 src/core/CLucene/util/_MD5Digester.h       |  1 -
 src/shared/CLucene/util/StringBuffer.cpp   | 25 ++++++++++---------
 6 files changed, 57 insertions(+), 34 deletions(-)

diff --git a/src/core/CLucene/debug/error.cpp b/src/core/CLucene/debug/error.cpp
index 9b4fe3ee..e661cb86 100644
--- a/src/core/CLucene/debug/error.cpp
+++ b/src/core/CLucene/debug/error.cpp
@@ -46,6 +46,18 @@ CL_NS_USE(util)
     }
 #endif
 	
+    	CLuceneError& CLuceneError::operator=(const CLuceneError& other)
+	{
+	    if (&other != this)
+	    {
+		_awhat = STRDUP_AtoA(other._awhat);
+	        _twhat = STRDUP_TtoT(other._twhat);
+	        error_number = other.error_number;
+	    }
+	    
+	    return *this;
+	}
+
 	CLuceneError::CLuceneError(const CLuceneError& clone)
 	{
 		this->error_number = clone.error_number;
diff --git a/src/core/CLucene/debug/error.h b/src/core/CLucene/debug/error.h
index 9fe980fa..62da1e62 100644
--- a/src/core/CLucene/debug/error.h
+++ b/src/core/CLucene/debug/error.h
@@ -70,6 +70,7 @@ class CLUCENE_EXPORT CLuceneError
 public:
 	CLuceneError();
 	CLuceneError(const CLuceneError& clone);
+    CLuceneError& operator=(const CLuceneError&);
 #ifndef _ASCII
 	CLuceneError(int num, const char* str, bool ownstr);
 #endif
diff --git a/src/core/CLucene/index/TermInfosReader.cpp b/src/core/CLucene/index/TermInfosReader.cpp
index 6ede797a..87e3bd83 100644
--- a/src/core/CLucene/index/TermInfosReader.cpp
+++ b/src/core/CLucene/index/TermInfosReader.cpp
@@ -26,7 +26,7 @@ CL_NS_DEF(index)
 
 
   TermInfosReader::TermInfosReader(Directory* dir, const char* seg, FieldInfos* fis, const int32_t readBufferSize):
-      directory (dir),fieldInfos (fis), indexTerms(NULL), indexInfos(NULL), indexPointers(NULL), indexDivisor(1)
+      directory (dir),fieldInfos (fis), indexTerms(NULL), indexInfos(NULL), indexPointers(NULL), indexDivisor(1), indexTermsLength(0)
   {
   //Func - Constructor.
   //       Reads the TermInfos file (.tis) and eventually the Term Info Index file (.tii)
@@ -172,18 +172,20 @@ CL_NS_DEF(index)
 
 	  SegmentTermEnum* enumerator = getEnum();
 
-	  if (
-	      enumerator != NULL //an enumeration exists
-	      && enumerator->term(false) != NULL // term is at or past current
-	      && position >= enumerator->position
-		  && position < (enumerator->position + totalIndexInterval)
-	     )
-	  {
-		  return scanEnum(position);			  // can avoid seek
-	  }
-
-    //random-access: must seek
-    seekEnum(position / totalIndexInterval);
+    if (enumerator != NULL) //an enumeration exists
+    {
+	    if (
+  	      enumerator->term(false) != NULL // term is at or past current
+  	      && position >= enumerator->position
+  		    && position < (enumerator->position + totalIndexInterval)
+  	     )
+	    {
+		      return scanEnum(position);			  // can avoid seek
+	    }
+
+      //random-access: must seek
+      seekEnum(position / totalIndexInterval);
+    }
 
 	//Get the Term at position
     return scanEnum(position);
diff --git a/src/core/CLucene/search/MultiSearcher.cpp b/src/core/CLucene/search/MultiSearcher.cpp
index 0f2a6862..1f8e99c6 100644
--- a/src/core/CLucene/search/MultiSearcher.cpp
+++ b/src/core/CLucene/search/MultiSearcher.cpp
@@ -207,16 +207,22 @@ CL_NS_DEF(search)
 	  _CLDELETE(docs);
     }
 
-    int32_t hqlen = hq->size();
-	fieldDocs = _CL_NEWARRAY(FieldDoc*,hqlen);
-	for (j = hqlen - 1; j >= 0; j--)	  // put docs in array
-      fieldDocs[j] = hq->pop();
-
-	SortField** hqFields = hq->getFields();
-	hq->setFields(NULL); //move ownership of memory over to TopFieldDocs
-    _CLDELETE(hq);
+    TopFieldDocs* pResult = NULL;
+    if (hq)
+    {
+      int32_t hqlen = hq->size();
+  	  fieldDocs = _CL_NEWARRAY(FieldDoc*,hqlen);
+    	for (j = hqlen - 1; j >= 0; j--)	  // put docs in array
+          fieldDocs[j] = hq->pop();
+
+    	SortField** hqFields = hq->getFields();
+    	hq->setFields(NULL); //move ownership of memory over to TopFieldDocs
+      _CLDELETE(hq);
+
+      pResult = _CLNEW TopFieldDocs (totalHits, fieldDocs, hqlen, hqFields);
+    }
 
-    return _CLNEW TopFieldDocs (totalHits, fieldDocs, hqlen, hqFields);
+    return pResult;
   }
 
   Query* MultiSearcher::rewrite(Query* query) {
diff --git a/src/core/CLucene/util/_MD5Digester.h b/src/core/CLucene/util/_MD5Digester.h
index aff913ac..e7060a24 100644
--- a/src/core/CLucene/util/_MD5Digester.h
+++ b/src/core/CLucene/util/_MD5Digester.h
@@ -102,7 +102,6 @@ private:
 	uint32_t		m_Count[2];
 	uint8_t		m_Buffer[64];
 	uint8_t		m_Digest[16];
-	uint8_t		m_Finalized;
 
 };
 
diff --git a/src/shared/CLucene/util/StringBuffer.cpp b/src/shared/CLucene/util/StringBuffer.cpp
index 63c78bb2..57ffcba5 100644
--- a/src/shared/CLucene/util/StringBuffer.cpp
+++ b/src/shared/CLucene/util/StringBuffer.cpp
@@ -292,14 +292,15 @@ CL_NS_DEF(util)
 
 	//Allocate a new buffer of length bufferLength
     TCHAR* tmp = _CL_NEWARRAY(TCHAR,bufferLength);
-    _tcsncpy(tmp, buffer, len);
-    tmp[len] = '\0';
+    if (buffer){
+      _tcsncpy(tmp, buffer, len);
+      tmp[len] = '\0';
 
-	//destroy the old buffer
-	if (buffer){
-		_CLDELETE_CARRAY(buffer);
-	}
-	//Assign the new buffer tmp to buffer
+	    //destroy the old buffer
+		  _CLDELETE_CARRAY(buffer);
+	  }
+
+	  //Assign the new buffer tmp to buffer
     buffer = tmp;
   }
 
@@ -337,11 +338,13 @@ CL_NS_DEF(util)
     //The old buffer might not have been null-terminated, so we _tcsncpy
     //only len bytes, not len+1 bytes (the latter might read one char off the
     //end of the old buffer), then apply the terminator to the new buffer.
-    _tcsncpy(tmp + skippingNInitialChars, buffer, len);
-    tmp[skippingNInitialChars + len] = '\0';
+    if (buffer) {
+      _tcsncpy(tmp + skippingNInitialChars, buffer, len);
+      tmp[skippingNInitialChars + len] = '\0';
 
-    //destroy the old buffer
-    _CLDELETE_LCARRAY(buffer);
+      //destroy the old buffer
+      _CLDELETE_LCARRAY(buffer);
+    }
 
 	//Assign the new buffer tmp to buffer
     buffer = tmp;
-- 
2.37.1 (Apple Git-137.1)