Skip to content

Commit fc19d62

Browse files
[svdconv] disableCondition Inheritance leads to a segment violation #1796 (#1176)
1 parent 1837b27 commit fc19d62

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

tools/svdconv/SVDModel/include/SvdCExpression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class SvdCExpression : public SvdElement
2424

2525
virtual bool CheckItem();
2626

27-
class Symbols_t {
27+
class Symbols {
2828
public:
2929
SvdCExpressionParser::token_s token;
3030
SvdItem* svdItem;
3131
std::list<std::string> searchname;
3232

33-
Symbols_t() {
33+
Symbols() {
3434
clear();
3535
}
3636
void clear() {
@@ -40,7 +40,7 @@ class SvdCExpression : public SvdElement
4040
token.type = SvdCExpressionParser::xme_what;
4141
}
4242
};
43-
using SymbolsList = std::list<Symbols_t>;
43+
using SymbolsList = std::list<Symbols>;
4444

4545
using RegList = std::map<std::string, SvdItem*>;
4646

tools/svdconv/SVDModel/include/SvdPeripheral.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class SvdPeripheral : public SvdItem
9090
bool CalcDisableCondition ();
9191
bool AddToMap (SvdEnum *enu, std::map<std::string, SvdEnum*> &map);
9292
bool CalculateMaxPaddingWidth ();
93+
bool CopyDisableCondition ( SvdCExpression* disableCondition);
94+
9395

9496
const std::string& GetVersion () { return m_version; }
9597
const std::string& GetGroupName () { return m_groupName; }
@@ -110,7 +112,6 @@ class SvdPeripheral : public SvdItem
110112
bool SetAlternate ( const std::string& alternate ) { m_alternate = alternate ; return true; }
111113
bool SetPrependToName ( const std::string& prependToName ) { m_prependToName = prependToName ; return true; }
112114
bool SetAppendToName ( const std::string& appendToName ) { m_appendToName = appendToName ; return true; }
113-
bool SetDisableCondition ( SvdCExpression* disableCondition) { m_disableCondition = disableCondition; return true; }
114115
bool SetAddress ( uint64_t address ) { m_address.u64 = address ; m_address.bValid = true; return true; }
115116
bool SetResetValue ( uint64_t resetValue ) { m_resetValue = resetValue ; return true; }
116117
bool SetResetMask ( uint64_t resetMask ) { m_resetMask = resetMask ; return true; }

tools/svdconv/SVDModel/src/SvdCExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool SvdCExpression::LinkSymbols(SvdItem* item, const SvdCExpressionParser::Toke
5252
}
5353

5454
m_symbolsList.clear();
55-
Symbols_t symbol;
55+
Symbols symbol;
5656
string errText;
5757

5858
for(const auto& token : tokens) {

tools/svdconv/SVDModel/src/SvdPeripheral.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ bool SvdPeripheral::CopyItem(SvdItem *from)
369369
if(alternate == "") { SetAlternate (pFrom->GetAlternate ()); }
370370
if(prependToName == "") { SetPrependToName (pFrom->GetPrependToName ()); }
371371
if(appendToName == "") { SetAppendToName (pFrom->GetAppendToName ()); }
372-
if(disableCondition == nullptr) { SetDisableCondition (pFrom->GetDisableCondition ()); } // TODO: Add a copy mechanism?
372+
if(disableCondition == nullptr) { CopyDisableCondition (pFrom->GetDisableCondition ()); } // TODO: Add a copy mechanism?
373373
if(address == 0 ) { SetAddress (pFrom->GetAddress ()); }
374374
if(resetValue == 0 ) { SetResetValue (pFrom->GetResetValue ()); }
375375
if(resetMask == 0 ) { SetResetMask (pFrom->GetResetMask ()); }
@@ -429,6 +429,17 @@ bool SvdPeripheral::CalculateMaxPaddingWidth()
429429
return true;
430430
}
431431

432+
bool SvdPeripheral::CopyDisableCondition(SvdCExpression* from)
433+
{
434+
if(!from) {
435+
return true;
436+
}
437+
438+
m_disableCondition = new SvdCExpression(*from);
439+
440+
return true;
441+
}
442+
432443
bool SvdPeripheral::Calculate()
433444
{
434445
CalculateMaxPaddingWidth();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<device xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" schemaVersion="1.3">
3+
<name>test</name>
4+
<version>1.0</version>
5+
<description>Test_Example device</description>
6+
<addressUnitBits>8</addressUnitBits>
7+
<width>32</width>
8+
<peripherals>
9+
<peripheral>
10+
<name>PeripheralA</name>
11+
<disableCondition>0 == 0</disableCondition>
12+
<baseAddress>0x40004000</baseAddress>
13+
<addressBlock>
14+
<offset>0x0</offset>
15+
<size>0x1000</size>
16+
<usage>registers</usage>
17+
</addressBlock>
18+
<registers>
19+
<register>
20+
<name>RegisterA</name>
21+
<addressOffset>0x0</addressOffset>
22+
</register>
23+
</registers>
24+
</peripheral>
25+
<peripheral derivedFrom="PeripheralA">
26+
<name>PeripheralB</name>
27+
<baseAddress>0x40002000</baseAddress>
28+
</peripheral>
29+
</peripherals>
30+
</device>

tools/svdconv/Test/integtests/src/SvdConvIntegTests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,14 @@ TEST_F(SvdConvIntegTests, CheckSauNumRegions_Errors) {
157157
FAIL() << "Occurrences of M219, M364 are wrong.";
158158
}
159159
}
160+
161+
// Validate NameHasBrackets
162+
TEST_F(SvdConvIntegTests, CheckAccViolationDisableCond) {
163+
const string& inFile = SvdConvIntegTestEnv::localtestdata_dir + "/accViolationDisableCond/accViolationDisableCond.xml";
164+
ASSERT_TRUE(RteFsUtils::Exists(inFile));
165+
166+
Arguments args("SVDConv.exe", inFile);
167+
168+
SvdConv svdConv;
169+
EXPECT_EQ(1, svdConv.Check(args, args, nullptr));
170+
}

0 commit comments

Comments
 (0)