Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

attached are 2 trivial patches to make the 'tools' directory build
with --enable-werror under CLang++. One of the change is actually an
existing off-by-one error caught by the compiler.

Those 2 patches are released under the LGPLv3+/MPL.

Thanks,
Julien
From ee8fe9239d607cb9e02d1e468d8232b84fb8b348 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <julien.chaffraix@gmail.com>
Date: Thu, 14 Apr 2011 22:48:29 -0700
Subject: [PATCH 1/2] 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.
---
 tools/source/debug/debug.cxx |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

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;
 }
-- 
1.7.1

From 529fd9eef5ff7420504ec2526d1262f2c1355a2f Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <julien.chaffraix@gmail.com>
Date: Thu, 14 Apr 2011 22:52:46 -0700
Subject: [PATCH 2/2] 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.
---
 tools/source/debug/debug.cxx |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

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]), "..." );
     }
-- 
1.7.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.