Skip to content
Browse files

Check return value of GetTempFileName - fixes #47

  • Loading branch information...
1 parent af0eaaf commit 9f9f38451a9f5c3d5b96e82516897ba3d4a6b487 @larsch committed Mar 15, 2012
Showing with 22 additions and 1 deletion.
  1. +7 −1 src/stub.c
  2. +15 −0 test/test_ocra.rb
View
8 src/stub.c
@@ -145,7 +145,13 @@ BOOL OpCreateInstDirectory(LPVOID *p)
} else {
GetTempPath(MAX_PATH, TempPath);
}
- GetTempFileName(TempPath, _T("ocrastub"), 0, InstDir);
+
+ UINT tempResult = GetTempFileName(TempPath, _T("ocrastub"), 0, InstDir);
+ if (tempResult == 0u) {
+ FATAL("Failed to get temp file name.");
+ return FALSE;
+ }
+
DEBUG("Creating installation directory: '%s'", InstDir);
/* Attempt to delete the temp file created by GetTempFileName.
View
15 test/test_ocra.rb
@@ -728,5 +728,20 @@ def test_explicit_in_exec_prefix
end
end
end
+
+ # Hello world test. Test that we can build and run executables.
+ def test_nonexistent_temp
+ with_fixture 'helloworld' do
+ assert system("ruby", ocra, "helloworld.rb", *DefaultArgs)
+ assert File.exist?("helloworld.exe")
+ pristine_env "helloworld.exe" do
+ with_env "TEMP" => "c:\\thispathdoesnotexist12345", "TMP" => "c:\\thispathdoesnotexist12345" do
+ assert File.exist?("helloworld.exe")
+ system("helloworld.exe 2>NUL")
+ assert File.exist?("helloworld.exe")
+ end
+ end
+ end
+ end
end

0 comments on commit 9f9f384

Please sign in to comment.
Something went wrong with that request. Please try again.