[BUGFIX]fix maat_compile_state_free null pointer
This commit is contained in:
@@ -55,16 +55,16 @@ bool operator!=(const uint128_t& lhs, const uint128_t& rhs)
|
||||
return !(lhs==rhs);
|
||||
}
|
||||
|
||||
//ִ<><D6B4>a-b<><62>aΪlhs<68><73>bΪrhs
|
||||
//ִ<><D6B4>a-b<><62>aΪlhs<68><73>bΪrhs
|
||||
uint128_t operator-(const uint128_t& lhs, const uint128_t& rhs)
|
||||
{
|
||||
uint128_t l = rhs;
|
||||
uint128_t h = lhs;
|
||||
unsigned long long I[2] = {0};
|
||||
if(h.I[0] < l.I[0])//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>λ
|
||||
if(h.I[0] < l.I[0])//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>λ
|
||||
{
|
||||
I[0] = ULONG_MAX - (l.I[0] - h.I[0]);
|
||||
h.I[1]--;//<2F><><EFBFBD><EFBFBD>λ<EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>λ<EFBFBD><CEBB>Ҫ<EFBFBD><D2AA>1
|
||||
h.I[1]--;//<2F><><EFBFBD><EFBFBD>λ<EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>λ<EFBFBD><CEBB>Ҫ<EFBFBD><D2AA>1
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -83,8 +83,8 @@ uint128_t operator-(const uint128_t& lhs, const uint128_t& rhs)
|
||||
|
||||
unsigned int ipv6_hash(const uint128_t * ip)
|
||||
{
|
||||
unsigned long long I=(ip->I[0])^(ip->I[1]);
|
||||
return (I&0xFFFFFFFF)^(I>>32);
|
||||
unsigned long long I = (ip->I[0])^(ip->I[1]);
|
||||
return (I & 0xFFFFFFFF)^(I >> 32);
|
||||
}
|
||||
|
||||
CInt128IntervalIndex::CInt128IntervalIndex()
|
||||
@@ -131,81 +131,76 @@ CInt128IntervalIndex::~CInt128IntervalIndex()
|
||||
|
||||
long long CInt128IntervalIndex::PreProcessing(const vector<uint128_t>& a, const vector<uint128_t>& b)
|
||||
{
|
||||
if(a.size()==0) return -1;
|
||||
if (a.size() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_is_single=true;
|
||||
for(unsigned int i=0; i<a.size(); i++)
|
||||
{
|
||||
if(a[i]!=b[i])
|
||||
{
|
||||
m_is_single=false;
|
||||
m_is_single = true;
|
||||
for (size_t i = 0; i < a.size(); i++) {
|
||||
if (a[i] != b[i]) {
|
||||
m_is_single = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_is_single)
|
||||
{
|
||||
if (m_is_single) {
|
||||
return process_single(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return process_interval(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
long long CInt128IntervalIndex::process_single(const vector<uint128_t>& a)
|
||||
{
|
||||
long long mem_bytes=0;
|
||||
unsigned int num=a.size();
|
||||
unsigned int * keys =new unsigned int[num];
|
||||
unsigned int * values=new unsigned int[num];
|
||||
m_array=new uint128_t[num];
|
||||
long long mem_bytes = 0;
|
||||
unsigned int num = a.size();
|
||||
unsigned int *keys = new unsigned int[num];
|
||||
unsigned int *values = new unsigned int[num];
|
||||
m_array = new uint128_t[num];
|
||||
|
||||
mem_bytes+=(2*sizeof(unsigned int)+sizeof(uint128_t))*num;
|
||||
mem_bytes += (2 * sizeof(unsigned int) + sizeof(uint128_t)) * num;
|
||||
|
||||
for(unsigned int i=0; i<num; i++)
|
||||
{
|
||||
keys[i]=ipv6_hash(&a[i]);
|
||||
values[i]=i;
|
||||
m_array[i]=a[i];
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
keys[i] = ipv6_hash(&a[i]);
|
||||
values[i] = i;
|
||||
m_array[i] = a[i];
|
||||
}
|
||||
|
||||
long long ret=m_ip_hash.init(keys, values, num);
|
||||
long long ret = m_ip_hash.init(keys, values, num);
|
||||
delete [] keys;
|
||||
delete [] values;
|
||||
if(ret<0) return -1;
|
||||
mem_bytes+=ret;
|
||||
mem_bytes += ret;
|
||||
|
||||
return mem_bytes;
|
||||
}
|
||||
|
||||
long long CInt128IntervalIndex::process_interval(const vector<uint128_t>& a, const vector<uint128_t>& b)
|
||||
{
|
||||
vector<uint128_t> A=a, B=b;
|
||||
long long iMemBytes=0;
|
||||
vector<uint128_t> A = a, B = b;
|
||||
long long iMemBytes = 0;
|
||||
|
||||
set<uint128_t> s;
|
||||
vector<unsigned int> IndexForMaxInt;
|
||||
vector<unsigned int> IndexForWholeInterval;
|
||||
for(int i=0, n=(int)A.size(); i<n; i++)
|
||||
{
|
||||
if(A[i]>B[i]) continue;
|
||||
|
||||
if(B[i].is_all_ones())
|
||||
{
|
||||
for (int i = 0, n = (int)A.size(); i<n; i++) {
|
||||
if (A[i] > B[i]) continue;
|
||||
|
||||
if (B[i].is_all_ones()) {
|
||||
IndexForMaxInt.push_back(i);
|
||||
--B[i];
|
||||
}
|
||||
++B[i]; // now A[i], B[i] is half closed interval.
|
||||
if(A[i]>=B[i]) continue;
|
||||
|
||||
if(A[i].is_all_zeros() && B[i].is_all_ones())
|
||||
{
|
||||
if (A[i] >= B[i]) continue;
|
||||
|
||||
if (A[i].is_all_zeros() && B[i].is_all_ones()) {
|
||||
IndexForWholeInterval.push_back(i);
|
||||
continue;
|
||||
}
|
||||
s.insert(A[i]);
|
||||
s.insert(B[i]);
|
||||
|
||||
}
|
||||
|
||||
m_IndexForWholeInterval=new unsigned int[IndexForWholeInterval.size()+1];
|
||||
@@ -286,45 +281,39 @@ long long CInt128IntervalIndex::process_interval(const vector<uint128_t>& a, con
|
||||
return iMemBytes;
|
||||
}
|
||||
|
||||
int CInt128IntervalIndex::Find(const uint128_t * key, unsigned int * result, unsigned int size)
|
||||
int CInt128IntervalIndex::Find(const uint128_t *key, unsigned int *result, unsigned int size)
|
||||
{
|
||||
if(m_is_single)
|
||||
{
|
||||
if (m_is_single) {
|
||||
return Find_single(key, result, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Find_interval(key, result, size);
|
||||
}
|
||||
}
|
||||
|
||||
int CInt128IntervalIndex::Find_single(const uint128_t * key, unsigned int * result, unsigned int size)
|
||||
int CInt128IntervalIndex::Find_single(const uint128_t *key, unsigned int *result, unsigned int size)
|
||||
{
|
||||
unsigned int h=ipv6_hash(key);
|
||||
int ret=m_ip_hash.find(h, result, size);
|
||||
unsigned int h = ipv6_hash(key);
|
||||
int ret = m_ip_hash.find(h, result, size);
|
||||
int j=0;
|
||||
for(int i=0; i<ret; i++)
|
||||
{
|
||||
if(*key==m_array[result[i]]) result[j++]=result[i];
|
||||
|
||||
for (int i = 0; i < ret; i++) {
|
||||
if(*key == m_array[result[i]]) result[j++] = result[i];
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
int CInt128IntervalIndex::Find_interval(const uint128_t * key, unsigned int * result, unsigned int size)
|
||||
int CInt128IntervalIndex::Find_interval(const uint128_t *key, unsigned int *result, unsigned int size)
|
||||
{
|
||||
if(key->is_all_ones())
|
||||
{
|
||||
unsigned int s=m_IndexForMaxInt[0];
|
||||
if(s>size) s=size;
|
||||
for(unsigned int i=1; i<=s; i++) *result++=m_IndexForMaxInt[i];
|
||||
if (key->is_all_ones()) {
|
||||
unsigned int s = m_IndexForMaxInt[0];
|
||||
if (s > size) s = size;
|
||||
for(unsigned int i = 1; i <= s; i++) *result++=m_IndexForMaxInt[i];
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int s=m_IndexForWholeInterval[0];
|
||||
if(s>size) s=size;
|
||||
for(unsigned int i=1; i<=s; i++)
|
||||
{
|
||||
} else {
|
||||
unsigned int s = m_IndexForWholeInterval[0];
|
||||
if (s > size) s = size;
|
||||
for (unsigned int i = 1; i <= s; i++) {
|
||||
*result++=m_IndexForWholeInterval[i];
|
||||
}
|
||||
size-=s;
|
||||
@@ -332,20 +321,22 @@ int CInt128IntervalIndex::Find_interval(const uint128_t * key, unsigned int * re
|
||||
unsigned int k = t.I[0]&0xffff;
|
||||
long long l=m_L[k], h=m_L[k+1];
|
||||
long long m=0;
|
||||
while(l<=h && m<m_iEndPointsNum)
|
||||
{
|
||||
m=(l+h)>>1;
|
||||
if(*key>=m_pEndPoints[m]) l=m+1;
|
||||
else h=m-1;
|
||||
|
||||
while (l <= h && m < m_iEndPointsNum) {
|
||||
m = (l+h)>>1;
|
||||
if (*key >= m_pEndPoints[m]) {
|
||||
l = m+1;
|
||||
} else {
|
||||
h = m-1;
|
||||
}
|
||||
}
|
||||
|
||||
if(h>=m_L[k] && h<m_iEndPointsNum)
|
||||
{
|
||||
long long n=m_pIDPtr[h+1]-m_pIDPtr[h];
|
||||
if(n>size) n=size;
|
||||
unsigned int * id_list=m_pIDList+m_pIDPtr[h];
|
||||
if (h >= m_L[k] && h < m_iEndPointsNum) {
|
||||
long long n = m_pIDPtr[h+1] - m_pIDPtr[h];
|
||||
if (n > size) n = size;
|
||||
unsigned int *id_list = m_pIDList + m_pIDPtr[h];
|
||||
for(unsigned int i=0; i<n; i++) *result++=*id_list++;
|
||||
s+=n;
|
||||
s += n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user