Skip to content

Commit 4b3e4df

Browse files
committed
Correct a crash in Amose
Thanks to ASAN for helping finding the problem
1 parent b7512fa commit 4b3e4df

File tree

16 files changed

+82
-68
lines changed

16 files changed

+82
-68
lines changed

lima_linguisticprocessing/src/linguisticProcessing/common/PropertyCode/PropertyCodeManager.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ string hexString(const uint128_t x)
5050
class PropertyCodeManagerPrivate
5151
{
5252
friend class PropertyCodeManager;
53+
public:
54+
PropertyCodeManagerPrivate() = default;
55+
~PropertyCodeManagerPrivate() = default;
56+
PropertyCodeManagerPrivate(const PropertyCodeManagerPrivate&) = delete;
57+
PropertyCodeManagerPrivate& operator=(const PropertyCodeManagerPrivate&) = delete;
5358

54-
std::map<std::string,PropertyManager> m_propertyManagers;
59+
std::map<std::string, PropertyManager> m_propertyManagers;
5560

5661
/**
5762
* @brief Compute the number of bit needed to encode nbvalues
@@ -74,18 +79,17 @@ class PropertyCodeManagerPrivate
7479
};
7580

7681
PropertyCodeManager::PropertyCodeManager() :
77-
m_d(new PropertyCodeManagerPrivate())
82+
m_d(std::make_unique<PropertyCodeManagerPrivate>())
7883
{
7984
}
8085

8186
PropertyCodeManager::~PropertyCodeManager()
8287
{
83-
delete m_d;
8488
}
8589

86-
PropertyCodeManager::PropertyCodeManager(const PropertyCodeManager& pcm)
90+
PropertyCodeManager::PropertyCodeManager(const PropertyCodeManager& pcm) :
91+
m_d(std::make_unique<PropertyCodeManagerPrivate>())
8792
{
88-
m_d = new PropertyCodeManagerPrivate();
8993
m_d->m_propertyManagers = pcm.m_d->m_propertyManagers;
9094
}
9195

lima_linguisticprocessing/src/linguisticProcessing/common/PropertyCode/PropertyCodeManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class LIMA_PROPERTYCODE_EXPORT PropertyCodeManager
116116
std::map<std::string,LinguisticCode>& conversionTable) const;
117117

118118
private:
119-
PropertyCodeManagerPrivate* m_d;
119+
std::unique_ptr<PropertyCodeManagerPrivate> m_d;
120120
};
121121

122122
} // PropertyCode

lima_linguisticprocessing/src/linguisticProcessing/common/PropertyCode/PropertyManager.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace PropertyCode
2323
class PropertyManagerPrivate
2424
{
2525
friend class PropertyManager;
26-
26+
public:
2727
PropertyManagerPrivate(const std::string& name,
2828
const LinguisticCode& mask,
2929
const LinguisticCode& emptyNessMask,
@@ -97,18 +97,17 @@ PropertyManager::PropertyManager(const std::string& name,
9797
const LinguisticCode& mask,
9898
const LinguisticCode& emptyNessMask,
9999
const std::map<std::string,LinguisticCode> symbol2code) :
100-
m_d(new PropertyManagerPrivate(name, mask, emptyNessMask, symbol2code))
100+
m_d(std::make_unique<PropertyManagerPrivate>(name, mask, emptyNessMask, symbol2code))
101101
{
102102
}
103103

104104
PropertyManager::~PropertyManager()
105105
{
106-
delete m_d;
107106
}
108107

109-
PropertyManager::PropertyManager(const PropertyManager& pm)
108+
PropertyManager::PropertyManager(const PropertyManager& pm) :
109+
m_d(std::make_unique<PropertyManagerPrivate>(*pm.m_d))
110110
{
111-
m_d = new PropertyManagerPrivate(*pm.m_d);
112111
}
113112

114113
PropertyManager& PropertyManager::operator=(const PropertyManager& pm)

lima_linguisticprocessing/src/linguisticProcessing/common/PropertyCode/PropertyManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class LIMA_PROPERTYCODE_EXPORT PropertyManager
108108
size_t getNbValues() const;
109109

110110
private:
111-
PropertyManagerPrivate* m_d;
111+
std::unique_ptr<PropertyManagerPrivate> m_d;
112112
};
113113

114114
#define GET_PROPERTY_MANAGER(language, property) \

lima_linguisticprocessing/src/linguisticProcessing/core/AnalysisDumpers/LTRTextBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void LTRTextBuilder::updateLTR_TokenFromVertex(
204204
LERROR << "Empty MorphoSyntacticData for vertex" << vertex << ", token=" << fullToken->stringForm();
205205
}
206206

207-
sort(data->begin(),data->end(),ltNormProperty(m_macroAccessor));
207+
sort(data->begin(),data->end(),ltNormProperty(*m_macroAccessor));
208208

209209
StringsPoolIndex norm(0),lastNorm(0);
210210
LinguisticCode macro,lastMacro;

lima_linguisticprocessing/src/linguisticProcessing/core/AnalysisDumpers/SimpleXmlDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ void SimpleXmlDumper::xmlOutputVertexInfos(
434434
uint64_t offset,
435435
LinguisticCode category) const
436436
{
437-
ltNormProperty sorter(m_propertyAccessor);
437+
ltNormProperty sorter(*m_propertyAccessor);
438438
auto position = ft->position() + offset;
439439

440440
auto output = false;

lima_linguisticprocessing/src/linguisticProcessing/core/AnalysisDumpers/TextDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void TextDumper::outputVertex(std::ostream& out,
213213
uint64_t offset) const
214214
{
215215

216-
ltNormProperty sorter(m_propertyAccessor);
216+
ltNormProperty sorter(*m_propertyAccessor);
217217

218218
// uint64_t nbmicros=ft->countMicros();
219219
std::ostringstream os;

lima_linguisticprocessing/src/linguisticProcessing/core/LinguisticAnalysisStructure/MorphoSyntacticDataUtils.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,59 +25,66 @@ bool ltString::operator()(const LinguisticElement& elem1,const LinguisticElement
2525
return elem1.properties < elem2.properties;
2626
}
2727

28-
ltProperty::ltProperty(const Common::PropertyCode::PropertyAccessor* prop) :
28+
ltProperty::ltProperty(const Common::PropertyCode::PropertyAccessor& prop) :
2929
m_prop(prop)
3030
{}
3131

3232
bool ltProperty::operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const
3333
{
34-
return m_prop->readValue(elem1.properties) < m_prop->readValue(elem2.properties);
34+
return m_prop.readValue(elem1.properties) < m_prop.readValue(elem2.properties);
3535
}
3636

37-
ltNormProperty::ltNormProperty(const Common::PropertyCode::PropertyAccessor* prop) :
37+
ltNormProperty::ltNormProperty(const Common::PropertyCode::PropertyAccessor& prop) :
3838
m_prop(prop)
3939
{}
4040

4141
bool ltNormProperty::operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const
4242
{
4343
if (elem1.normalizedForm!=elem2.normalizedForm) return elem1.normalizedForm < elem2.normalizedForm;
44-
return m_prop->readValue(elem1.properties) < m_prop->readValue(elem2.properties);
44+
return m_prop.readValue(elem1.properties) < m_prop.readValue(elem2.properties);
4545
}
4646

47-
CheckEqualPropertyPredicate::CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value) :
47+
CheckEqualPropertyPredicate::CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,LinguisticCode value) :
4848
m_property(prop),
4949
m_value(value)
5050
{}
5151

5252
bool CheckEqualPropertyPredicate::operator()(const LinguisticElement& elem) const
5353
{
54-
return m_property->equal(elem.properties,m_value);
54+
return m_property.equal(elem.properties,m_value);
5555
}
5656

57-
CheckDifferentPropertyPredicate::CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value) :
57+
CheckDifferentPropertyPredicate::CheckDifferentPropertyPredicate(
58+
const Common::PropertyCode::PropertyAccessor& prop,
59+
LinguisticCode value) :
5860
m_property(prop),
5961
m_value(value)
6062
{}
6163

6264
bool CheckDifferentPropertyPredicate::operator()(const LinguisticElement& elem) const
6365
{
64-
return !(m_property->equal(elem.properties,m_value));
66+
return !(m_property.equal(elem.properties,m_value));
6567
}
6668

67-
IncludePropertyPredicate::IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& values) :
69+
IncludePropertyPredicate::IncludePropertyPredicate(
70+
const Common::PropertyCode::PropertyAccessor& prop,
71+
const std::set<LinguisticCode>& values) :
6872
m_property(prop),
6973
m_values(values)
7074
{}
7175

7276
bool IncludePropertyPredicate::operator()(const LinguisticElement& elem) const
7377
{
74-
return (m_values.find(m_property->readValue(elem.properties)) != m_values.end());
78+
return (m_values.find(m_property.readValue(elem.properties)) != m_values.end());
7579
}
7680

77-
ExcludePropertyPredicate::ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& values) :
81+
ExcludePropertyPredicate::ExcludePropertyPredicate(
82+
const Common::PropertyCode::PropertyAccessor& prop,
83+
const std::set<LinguisticCode>& values) :
7884
m_property(prop),
7985
m_values(values)
80-
{}
86+
{
87+
}
8188

8289
ExcludePropertyPredicate::ExcludePropertyPredicate(const ExcludePropertyPredicate& epp) :
8390
m_property(epp.m_property),
@@ -87,7 +94,7 @@ ExcludePropertyPredicate::ExcludePropertyPredicate(const ExcludePropertyPredicat
8794

8895
bool ExcludePropertyPredicate::operator()(const LinguisticElement& elem) const
8996
{
90-
return (m_values.find(m_property->readValue(elem.properties)) == m_values.end());
97+
return (m_values.find(m_property.readValue(elem.properties)) == m_values.end());
9198
}
9299

93100
} // LinguisticAnalysisStructure

lima_linguisticprocessing/src/linguisticProcessing/core/LinguisticAnalysisStructure/MorphoSyntacticDataUtils.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,69 @@ class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltString
3131
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltProperty
3232
{
3333
public:
34-
ltProperty(const Common::PropertyCode::PropertyAccessor* prop);
35-
bool operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const;
34+
ltProperty(const Common::PropertyCode::PropertyAccessor& prop);
35+
bool operator()(const LinguisticElement& elem1,
36+
const LinguisticElement& elem2) const;
3637
private:
37-
const Common::PropertyCode::PropertyAccessor* m_prop;
38+
Common::PropertyCode::PropertyAccessor m_prop;
3839
};
3940

4041
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ltNormProperty
4142
{
4243
public:
43-
ltNormProperty(const Common::PropertyCode::PropertyAccessor* prop);
44-
bool operator()(const LinguisticElement& elem1,const LinguisticElement& elem2) const;
44+
ltNormProperty(const Common::PropertyCode::PropertyAccessor& prop);
45+
bool operator()(const LinguisticElement& elem1,
46+
const LinguisticElement& elem2) const;
4547
private:
46-
const Common::PropertyCode::PropertyAccessor* m_prop;
48+
Common::PropertyCode::PropertyAccessor m_prop;
4749
};
4850

4951
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT CheckEqualPropertyPredicate
5052
{
5153
public:
52-
CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value);
54+
CheckEqualPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
55+
LinguisticCode value);
5356
bool operator()(const LinguisticElement& elem) const;
5457
private:
55-
const Common::PropertyCode::PropertyAccessor* m_property;
58+
const Common::PropertyCode::PropertyAccessor m_property;
5659
LinguisticCode m_value;
5760
};
5861

5962
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT CheckDifferentPropertyPredicate
6063
{
6164
public:
62-
CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,LinguisticCode value);
65+
CheckDifferentPropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
66+
LinguisticCode value);
6367
bool operator()(const LinguisticElement& elem) const;
6468
private:
65-
const Common::PropertyCode::PropertyAccessor* m_property;
69+
Common::PropertyCode::PropertyAccessor m_property;
6670
LinguisticCode m_value;
6771
};
6872

6973
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT IncludePropertyPredicate
7074
{
7175
public:
72-
IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,const std::set<LinguisticCode>& value);
76+
IncludePropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
77+
const std::set<LinguisticCode>& value);
7378
bool operator()(const LinguisticElement& elem) const;
7479
private:
7580
IncludePropertyPredicate& operator=(const IncludePropertyPredicate&) {return *this;}
76-
const Common::PropertyCode::PropertyAccessor* m_property;
81+
Common::PropertyCode::PropertyAccessor m_property;
7782
const std::set<LinguisticCode>& m_values;
7883
};
7984

8085
class LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT ExcludePropertyPredicate
8186
{
8287
public:
83-
ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor* prop,
88+
ExcludePropertyPredicate(const Common::PropertyCode::PropertyAccessor& prop,
8489
const std::set<LinguisticCode>& value);
8590
ExcludePropertyPredicate(const ExcludePropertyPredicate& epp);
8691

8792
bool operator()(const LinguisticElement& elem) const;
8893

8994
private:
9095
ExcludePropertyPredicate& operator=(const ExcludePropertyPredicate&) {return *this;}
91-
const Common::PropertyCode::PropertyAccessor* m_property;
96+
Common::PropertyCode::PropertyAccessor m_property;
9297
const std::set<LinguisticCode>& m_values;
9398
};
9499

lima_linguisticprocessing/src/linguisticProcessing/core/PosTagger/DynamicSvmToolPosTagger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ LimaStatusCode DynamicSvmToolPosTagger::process(AnalysisContent& analysis) const
292292
if (morphoData!=0)
293293
{
294294
LinguisticAnalysisStructure::MorphoSyntacticData* posData=new LinguisticAnalysisStructure::MorphoSyntacticData();
295-
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(m_microAccessor, code);
295+
LinguisticAnalysisStructure::CheckDifferentPropertyPredicate differentMicro(*m_microAccessor, code);
296296
std::back_insert_iterator<LinguisticAnalysisStructure::MorphoSyntacticData> backInsertItr(*posData);
297297
remove_copy_if(morphoData->begin(),morphoData->end(),backInsertItr,differentMicro);
298298
if (posData->empty() || morphoData->empty()) {

0 commit comments

Comments
 (0)