[Libreoffice-commits] .: 2 commits - tools/source
Caolán McNamara
caolan at kemper.freedesktop.org
Tue Apr 19 01:48:41 PDT 2011
tools/source/debug/debug.cxx | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
New commits:
commit 0b657e40c1e2db5e91a1c1f7a643f1f6954ecd7a
Author: Julien Chaffraix <julien.chaffraix at gmail.com>
Date: Thu Apr 14 22:52:46 2011 -0700
Fixed an off-by-one error in DbgOut.
"..." is actually 4 characters long due to the '\0' character and
strcpy does copy the '\0'. Thus we need to remove 4 from the length
to avoid writing one byte after the end of the buffer.
diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx
index f5c8698..8a6754e 100644
--- a/tools/source/debug/debug.cxx
+++ b/tools/source/debug/debug.cxx
@@ -1701,7 +1701,7 @@ void DbgOut( const sal_Char* pMsg, sal_uInt16 nDbgOut, const sal_Char* pFile, sa
int nMsgLen = strlen( pMsg );
if ( nBufLen+nMsgLen > DBG_BUF_MAXLEN )
{
- int nCopyLen = DBG_BUF_MAXLEN-nBufLen-3;
+ int nCopyLen = DBG_BUF_MAXLEN-nBufLen-4;
strncpy( &(aBufOut[nBufLen]), pMsg, nCopyLen );
strcpy( &(aBufOut[nBufLen+nCopyLen]), "..." );
}
commit 4fd6355d980f1273a6dd29e9559918dd170f5791
Author: Julien Chaffraix <julien.chaffraix at gmail.com>
Date: Thu Apr 14 22:48:29 2011 -0700
Added check for getcwd and chdir return values.
The code did not validate that those functions succeeded. Added
some error handling. This partially fixes the compilation with --werror.
diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx
index 167d8fd..f5c8698 100644
--- a/tools/source/debug/debug.cxx
+++ b/tools/source/debug/debug.cxx
@@ -37,6 +37,7 @@
#include <direct.h>
#endif
+#include <errno.h>
#include <time.h>
#include <cstdarg> // combinations
#include <stdlib.h>
@@ -827,7 +828,11 @@ static DebugData* GetDebugData()
}
- getcwd( aCurPath, sizeof( aCurPath ) );
+ sal_Char* getcwdResult = getcwd( aCurPath, sizeof( aCurPath ) );
+ if ( !getcwdResult )
+ {
+ OSL_TRACE( "getcwd failed with error %s", strerror(errno) );
+ }
// Daten initialisieren
if ( aDebugData.aDbgData.nTestFlags & DBG_TEST_XTOR )
@@ -856,8 +861,17 @@ static FILETYPE ImplDbgInitFile()
static sal_Bool bFileInit = sal_False;
sal_Char aBuf[4096];
- getcwd( aBuf, sizeof( aBuf ) );
- chdir( aCurPath );
+ sal_Char* getcwdResult = getcwd( aBuf, sizeof( aBuf ) );
+ if ( !getcwdResult ) {
+ OSL_TRACE( "getcwd failed with error = %s", strerror(errno) );
+ return NULL;
+ }
+
+ int chdirResult = chdir( aCurPath );
+ if ( !chdirResult ) {
+ OSL_TRACE ( "chdir failed with error = %s", strerror(errno) );
+ return NULL;
+ }
DebugData* pData = GetDebugData();
FILETYPE pDebugFile;
@@ -892,7 +906,11 @@ static FILETYPE ImplDbgInitFile()
else
pDebugFile = FileOpen( pData->aDbgData.aDebugName, "a" );
- chdir( aBuf );
+ chdirResult = chdir( aBuf );
+ if ( !chdirResult )
+ {
+ OSL_TRACE( "chdir failed with error = %s", strerror(errno) );
+ }
return pDebugFile;
}
More information about the Libreoffice-commits
mailing list