Exception in StdStorage::Read(). v7.5.0

Hello gents

I get an exception attempting to read the attached file using 

Handle(StdStorage_Data) data;

Storage_Error res = StdStorage::Read(fileName, data);                   assert((res == Storage_VSOk));

I am on Windows

The issue seems to be obvious:

FSD_CmpFile::ReadString(TCollection_AsciiString& buffer) has line 

aBuf.SetValue(lv, '\0');

But '\0' is not acceptable for TCollection_AsciiString::SetValue():

void TCollection_AsciiString::SetValue (const Standard_Integer theWhere,
                                        const Standard_Character theWhat)
{
  if (theWhere <= 0 || theWhere > mylength)
  {
    throw Standard_OutOfRange ("TCollection_AsciiString::SetValue(): out of range location");
  }
  else if (theWhat == '\0')
  {
    throw Standard_OutOfRange ("TCollection_AsciiString::SetValue(): NULL terminator is passed");
  }
  mystring[theWhere - 1] = theWhat;
}

Whole FSD_CmpFile::ReadString(TCollection_AsciiString& buffer):

//=======================================================================
//function : ReadString
//purpose  : read from the first none space character position to the end of line.
//=======================================================================

void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
{
  buffer.Clear();
  TCollection_AsciiString aBuf('\0');
  FSD_File::ReadString(aBuf);
  for (Standard_Integer lv = aBuf.Length(); lv >= 1 && (aBuf.Value(lv) == '\r' || (aBuf.Value(lv) == '\n')); lv--)
    aBuf.SetValue(lv, '\0');
  buffer = aBuf;
}

This happens when aBuf in CmpFile::ReadString() is "\r". 

Am I doing something wrong?

Thank you

Attachments: 
Nikolai's picture

I have fixed it for myself by changing else if (theWhat == '\0') case in TCollection_AsciiString::SetValue() to:

.....

else if (theWhat == '\0')
  {
      //throw Standard_OutOfRange ("TCollection_AsciiString::SetValue(): NULL terminator is passed");
      mylength = theWhere;
  }

mystring[theWhere - 1] = theWhat;
}

But there are more problems with the functionality.

One is easy that the call crashes if there is no new line in the end of the file.

The other one is tricky. I will post another thread for that.

Kirill Gavrilov's picture

If you would like the fix appear in OCCT, you may start from registering the issue on Bugtracker, which hopefully wouldn't take much time.

Nikolai's picture

I have added "0031968: EXCEPTION IN STDSTORAGE::READ()" to the bug tracker

Thanks