Fix few clang analyzer warnings (dotnet/coreclr#11185)
authorJan Vorlicek <janvorli@microsoft.com>
Wed, 26 Apr 2017 08:52:35 +0000 (01:52 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2017 08:52:35 +0000 (01:52 -0700)
This change fixes two issues reported by the clang analyzer. In both cases, uninitialized
variable value was used in an error code path.

Commit migrated from https://github.com/dotnet/coreclr/commit/3011ab330532cbd6f82da9b8ae5d1d28c324cc06

src/coreclr/src/pal/src/file/disk.cpp
src/coreclr/src/pal/src/file/file.cpp

index 08880c9..e5d6f83 100644 (file)
@@ -68,6 +68,7 @@ GetDiskFreeSpaceW(
     PathCharString dirNameBufferPathString;
     size_t length;
     char * dirNameBuffer;
+    const char * dirName;
     int size;
 
     PERF_ENTRY(GetDiskFreeSpaceW);
@@ -125,7 +126,7 @@ GetDiskFreeSpaceW(
         if ( size != 0 )
         {
             FILEDosToUnixPathA( dirNameBuffer );
-            statfsRetVal = statfs( dirNameBuffer, &fsInfoBuffer );
+            dirName = dirNameBuffer;
         }
         else
         {
@@ -136,9 +137,11 @@ GetDiskFreeSpaceW(
     }
     else
     {
-        statfsRetVal = statfs( "/", &fsInfoBuffer );
+        dirName = "/";
     }
 
+    statfsRetVal = statfs( dirName, &fsInfoBuffer );
+
     if ( statfsRetVal == 0 )
     {
         *lpBytesPerSector = fsInfoBuffer.f_bsize;
index d70e62b..a4ad20d 100644 (file)
@@ -2999,8 +2999,11 @@ OUT  PLARGE_INTEGER lpFileSize)
             &dwFileSizeHigh
             );
 
-        lpFileSize->u.LowPart = dwFileSizeLow;
-        lpFileSize->u.HighPart = dwFileSizeHigh;
+        if (NO_ERROR == palError)
+        {
+            lpFileSize->u.LowPart = dwFileSizeLow;
+            lpFileSize->u.HighPart = dwFileSizeHigh;
+        }
     }
     else
     {