1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0023567: Wrong STEP unit is returned by STEPControl_Reader.FileUnits() function

Fix bug with using of uninitialized variable.
New version of patch: pass unit object to the getSiName() function directly.
Test case for this bug
This commit is contained in:
vsr 2012-11-23 15:44:47 +04:00
parent 4e76d93bf1
commit e9c15c4cec
2 changed files with 40 additions and 24 deletions

View File

@ -433,34 +433,35 @@ void STEPControl_Reader::FileUnits( TColStd_SequenceOfAsciiString& theUnitLength
//purpose :
//=======================================================================
inline static TCollection_AsciiString getSiName(StepBasic_SiUnitName theName,
StepBasic_SiPrefix thePrefix)
inline static TCollection_AsciiString getSiName(const Handle(StepBasic_SiUnit)& theUnit)
{
TCollection_AsciiString aName;
switch (thePrefix) {
case StepBasic_spExa: aName += "exa"; break;
case StepBasic_spPeta: aName += "peta"; break;
case StepBasic_spTera: aName += "tera"; break;
case StepBasic_spGiga: aName += "giga"; break;
case StepBasic_spMega: aName += "mega"; break;
case StepBasic_spHecto: aName += "hecto"; break;
case StepBasic_spDeca: aName += "deca"; break;
case StepBasic_spDeci: aName += "deci"; break;
case StepBasic_spPico: aName += "pico"; break;
case StepBasic_spFemto: aName += "femto"; break;
case StepBasic_spAtto: aName += "atto"; break;
case StepBasic_spKilo : aName += "kilo"; break;
case StepBasic_spCenti :aName += "centi"; break;
case StepBasic_spMilli :aName += "milli"; break;
case StepBasic_spMicro :aName += "micro"; break;
case StepBasic_spNano :aName += "nano"; break;
default: break;
if (theUnit->HasPrefix()) {
switch (theUnit->Prefix()) {
case StepBasic_spExa: aName += "exa"; break;
case StepBasic_spPeta: aName += "peta"; break;
case StepBasic_spTera: aName += "tera"; break;
case StepBasic_spGiga: aName += "giga"; break;
case StepBasic_spMega: aName += "mega"; break;
case StepBasic_spHecto: aName += "hecto"; break;
case StepBasic_spDeca: aName += "deca"; break;
case StepBasic_spDeci: aName += "deci"; break;
case StepBasic_spPico: aName += "pico"; break;
case StepBasic_spFemto: aName += "femto"; break;
case StepBasic_spAtto: aName += "atto"; break;
case StepBasic_spKilo : aName += "kilo"; break;
case StepBasic_spCenti :aName += "centi"; break;
case StepBasic_spMilli :aName += "milli"; break;
case StepBasic_spMicro :aName += "micro"; break;
case StepBasic_spNano :aName += "nano"; break;
default: break;
};
}
switch(theName) {
switch(theUnit->Name()) {
case StepBasic_sunMetre : aName += "metre"; break;
case StepBasic_sunRadian : aName += "radian"; break;
case StepBasic_sunSteradian : aName += "steradian"; break;
@ -540,7 +541,7 @@ Standard_Boolean STEPControl_Reader::findUnits(
continue;
anUnitFact = (!aSiUnit->HasPrefix() ?
1. : STEPConstruct_UnitContext::ConvertSiPrefix(aSiUnit->Prefix()));
aName = getSiName(aSiUnit->Name(), aSiUnit->Prefix());
aName = getSiName(aSiUnit);
}

15
tests/bugs/step/bug23567 Executable file
View File

@ -0,0 +1,15 @@
puts "========================"
puts "OCC23567"
puts "========================"
puts ""
#######################################################################
# Wrong STEP unit is returned by STEPControl_Reader.FileUnits() function
#######################################################################
set info [ stepfileunits [locate_data_file bug23567_a.step] ]
set index1 [lsearch $info metre]
puts ""
if { ${index1} == -1 } {
puts "Error : bad unit"
}