Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exception location information in release builds. #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libplatform/io/FileSystem_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ getAttributes ( string path_ )
// the places it's called.
ostringstream msg;
msg << "can't convert file to UTF-16(" << filename.utf8 << ")";
throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__);
throw new EXCEPTION(msg.str());
}

DWORD attributes = ::GetFileAttributesW(filename);
Expand All @@ -49,7 +49,7 @@ getAttributes ( string path_ )
// Anything else is an error
ostringstream msg;
msg << "GetFileAttributes(" << filename.utf8 << ") failed (" << last_err << ")";
throw new Exception(msg.str(),__FILE__,__LINE__,__FUNCTION__);
throw new EXCEPTION(msg.str());
}

// path exists so return its attributes
Expand Down
10 changes: 5 additions & 5 deletions libutil/TrackModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TrackModifier::fromString( const string& src, bool& dst )
if( iss.rdstate() != ios::eofbit ) {
ostringstream oss;
oss << "invalid value: " << src;
throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str());
}
}

Expand All @@ -160,7 +160,7 @@ TrackModifier::fromString( const string& src, float& dst )
if( iss.rdstate() != ios::eofbit ) {
ostringstream oss;
oss << "invalid value: " << src;
throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str());
}

return dst;
Expand All @@ -176,7 +176,7 @@ TrackModifier::fromString( const string& src, uint16_t& dst )
if( iss.rdstate() != ios::eofbit ) {
ostringstream oss;
oss << "invalid value: " << src;
throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str());
}

return dst;
Expand All @@ -203,7 +203,7 @@ TrackModifier::refTrackAtom( MP4File& file, uint16_t index )
if( !trak ) {
oss.str( "" );
oss << "trackIndex " << index << " not found";
throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str());
}

return *trak;
Expand Down Expand Up @@ -474,7 +474,7 @@ TrackModifier::Properties::refProperty( const char* name )
if( !_trackModifier._track.FindProperty( name, &property )) {
ostringstream oss;
oss << "trackId " << _trackModifier.trackId << " property '" << name << "' not found";
throw new Exception( oss.str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str());
}

return *property;
Expand Down
2 changes: 1 addition & 1 deletion src/3gp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void MP4File::Make3GPCompliant(const char* fileName, char* majorBrand, uint32_t

if (majorBrand) {
if (!supportedBrands || !supportedBrandsCount) {
throw new Exception("Invalid parameters", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("Invalid parameters");
}
}

Expand Down
34 changes: 31 additions & 3 deletions src/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ namespace mp4v2 { namespace impl {

///////////////////////////////////////////////////////////////////////////////

Exception::Exception( const string& what_ )
: what(what_)
, line(0)
{
}

///////////////////////////////////////////////////////////////////////////////

Exception::Exception( const string& what_,
const char *file_,
int line_,
Expand All @@ -55,13 +63,28 @@ Exception::msg() const
{
ostringstream retval;

retval << function << ": " << what << " (" << file << "," << line << ")";
if( !function.empty() )
retval << function << ": ";

retval << what;

if( !file.empty() )
retval << " (" << file << "," << line << ")";

return retval.str();
}

///////////////////////////////////////////////////////////////////////////////

PlatformException::PlatformException( const string& what_,
int errno_ )
: Exception(what_)
, m_errno(errno_)
{
}

///////////////////////////////////////////////////////////////////////////////

PlatformException::PlatformException( const string& what_,
int errno_,
const char *file_,
Expand All @@ -85,8 +108,13 @@ PlatformException::msg() const
{
ostringstream retval;

retval << function << ": " << what << ": errno: " << m_errno << " (" <<
file << "," << line << ")";
if( !function.empty() )
retval << function << ": ";

retval << what << ": errno: " << m_errno;

if( !file.empty() )
retval << " (" << file << "," << line << ")";

return retval.str();
}
Expand Down
11 changes: 11 additions & 0 deletions src/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ namespace mp4v2 { namespace impl {

///////////////////////////////////////////////////////////////////////////////

#ifdef NDEBUG
#define EXCEPTION(message) mp4v2::impl::Exception(message)
#define PLATFORM_EXCEPTION(message, errno) mp4v2::impl::PlatformException(message, errno)
#else
#define EXCEPTION(message) mp4v2::impl::Exception(message, __FILE__, __LINE__, __FUNCTION__)
#define PLATFORM_EXCEPTION(message, errno) mp4v2::impl::PlatformException(message, errno, __FILE__, __LINE__, __FUNCTION__)
#endif

class MP4V2_EXPORT Exception
{
public:
explicit Exception( const string& what_ );
explicit Exception( const string& what_,
const char *file_,
int line_,
Expand All @@ -50,6 +59,8 @@ class MP4V2_EXPORT Exception
class MP4V2_EXPORT PlatformException : public Exception
{
public:
explicit PlatformException( const string& what_,
int errno_ );
explicit PlatformException( const string& what_,
int errno_,
const char *file_,
Expand Down
4 changes: 3 additions & 1 deletion src/isma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static const uint8_t BifsV2Config[3] = {

void MP4File::MakeIsmaCompliant(bool addIsmaComplianceSdp)
{
ProtectWriteOperation(__FILE__, __LINE__, __FUNCTION__);
if( !IsWriteMode() ) {
throw new EXCEPTION("operation not permitted in read mode");
}

if (m_useIsma) {
// already done
Expand Down
8 changes: 4 additions & 4 deletions src/mp4array.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MP4Array {
\
void Insert(type newElement, MP4ArrayIndex newIndex) { \
if (newIndex > m_numElements) { \
throw new PlatformException("illegal array index", ERANGE, __FILE__, __LINE__, __FUNCTION__); \
throw new PLATFORM_EXCEPTION("illegal array index", ERANGE); \
} \
if (m_numElements == m_maxNumElements) { \
m_maxNumElements = max(m_maxNumElements, (MP4ArrayIndex)1) * 2; \
Expand All @@ -91,7 +91,7 @@ class MP4Array {
if (!ValidIndex(index)) { \
ostringstream msg; \
msg << "illegal array index: " << index << " of " << m_numElements; \
throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__); \
throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); \
} \
m_numElements--; \
if (index < m_numElements) { \
Expand All @@ -103,7 +103,7 @@ class MP4Array {
m_numElements = newSize; \
m_maxNumElements = newSize; \
if ( (uint64_t) m_maxNumElements * sizeof(type) > 0xFFFFFFFF ) \
throw new PlatformException("requested array size exceeds 4GB", ERANGE, __FILE__, __LINE__, __FUNCTION__); /* prevent overflow */ \
throw new PLATFORM_EXCEPTION("requested array size exceeds 4GB", ERANGE); /* prevent overflow */ \
m_elements = (type*)MP4Realloc(m_elements, \
m_maxNumElements * sizeof(type)); \
} \
Expand All @@ -115,7 +115,7 @@ class MP4Array {
else { \
ostringstream msg; \
msg << "illegal array index: " << index << " of " << m_numElements; \
throw new PlatformException(msg.str().c_str(), ERANGE, __FILE__, __LINE__, __FUNCTION__ ); \
throw new PLATFORM_EXCEPTION(msg.str().c_str(), ERANGE); \
} \
} \
\
Expand Down
4 changes: 2 additions & 2 deletions src/mp4atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ MP4Atom* MP4Atom::ReadAtom(MP4File& file, MP4Atom* pParentAtom)
ostringstream oss;
oss << "Invalid atom size in '" << type << "' atom, dataSize = " << dataSize << " cannot be less than hdrSize = " << static_cast<unsigned>( hdrSize );
log.errorf( "%s: \"%s\": %s", __FUNCTION__, file.GetFilename().c_str(), oss.str().c_str() );
throw new Exception( oss.str().c_str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str().c_str());
}
dataSize -= hdrSize;

Expand Down Expand Up @@ -396,7 +396,7 @@ void MP4Atom::ReadProperties(uint32_t startIndex, uint32_t count)

ostringstream oss;
oss << "atom '" << GetType() << "' is too small; overrun at property: " << m_pProperties[i]->GetName();
throw new Exception( oss.str().c_str(), __FILE__, __LINE__, __FUNCTION__ );
throw new EXCEPTION(oss.str().c_str());
}

MP4LogLevel thisVerbosity =
Expand Down
16 changes: 8 additions & 8 deletions src/mp4container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void MP4Container::FindIntegerProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex)
{
if (!FindProperty(name, ppProperty, pIndex)) {
throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("no such property");
}

switch ((*ppProperty)->GetType()) {
Expand All @@ -71,7 +71,7 @@ void MP4Container::FindIntegerProperty(const char* name,
case Integer64Property:
break;
default:
throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("type mismatch");
}
}

Expand Down Expand Up @@ -99,10 +99,10 @@ void MP4Container::FindFloatProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex)
{
if (!FindProperty(name, ppProperty, pIndex)) {
throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("no such property");
}
if ((*ppProperty)->GetType() != Float32Property) {
throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("type mismatch");
}
}

Expand Down Expand Up @@ -130,10 +130,10 @@ void MP4Container::FindStringProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex)
{
if (!FindProperty(name, ppProperty, pIndex)) {
throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("no such property");
}
if ((*ppProperty)->GetType() != StringProperty) {
throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("type mismatch");
}
}

Expand Down Expand Up @@ -161,10 +161,10 @@ void MP4Container::FindBytesProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex)
{
if (!FindProperty(name, ppProperty, pIndex)) {
throw new Exception("no such property", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("no such property");
}
if ((*ppProperty)->GetType() != BytesProperty) {
throw new Exception("type mismatch", __FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("type mismatch");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mp4descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void MP4Descriptor::ReadProperties(MP4File& file,
} else {
log.errorf("%s: \"%s\": Overran descriptor, tag %u data size %u property %u",
__FUNCTION__, file.GetFilename().c_str(), m_tag, m_size, i);
throw new Exception("overran descriptor",__FILE__, __LINE__, __FUNCTION__);
throw new EXCEPTION("overran descriptor");
}
}
}
Expand Down
Loading