Although our build system doesn't complain, my local Linux gcc generates
several
warnings which prevent jpackage from building. The attached patch makes
it happy.
There are several of these :-
jpackage/open/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp:
In member function ‘virtual bool IniFile::GetSection(TString,
OrderedMap<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >&)’:
/home/prrace/jpackage/open/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp:192:25:
error: ‘section’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
IniSectionData* section;
A couple of complains about not checking the return value of chdir. My
patch throws an exception
which I think is better than ignoring it and using the wrong directory.
jpackage/open/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp:
In member function ‘virtual void
LinuxPlatform::SetCurrentDirectory(TString)’:
/home/prrace/jpackage/open/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp:129:52:
error: ignoring return value of ‘int chdir(const char*)’, declared with
attribute warn_unused_result [-Werror=unused-result]
chdir(PlatformString(Value).toPlatformString());
^
And this :
jpackage/open/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp:
In member function ‘virtual void PosixProcess::SetInput(TString)’:
/home/prrace/jpackage/open/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp:313:56:
error: ignoring return value of ‘ssize_t write(int, const void*,
size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
write(FInputHandle, Value.data(), Value.size());
^
cc1plus: all warnings being treated as errors
-phil.
diff --git a/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp b/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp
--- a/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp
+++ b/src/jdk.jpackage/linux/native/libapplauncher/LinuxPlatform.cpp
@@ -126,7 +126,12 @@
}
void LinuxPlatform::SetCurrentDirectory(TString Value) {
- chdir(PlatformString(Value).toPlatformString());
+
+ if (chdir(PlatformString(Value).toPlatformString())) {
+ TString message = PlatformString::Format(
+ _T("Error: Unable to chdir to %s"), Value);
+ throw Exception(message);
+ }
}
TString LinuxPlatform::GetPackageRootDirectory() {
diff --git a/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp b/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp
--- a/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp
+++ b/src/jdk.jpackage/share/native/libapplauncher/IniFile.cpp
@@ -159,7 +159,7 @@
bool IniFile::GetValue(const TString SectionName,
const TString Key, TString& Value) {
bool result = false;
- IniSectionData* section;
+ IniSectionData* section = NULL;
if (FMap.GetValue(SectionName, section) == true && section != NULL) {
result = section->GetValue(Key, Value);
@@ -171,7 +171,7 @@
bool IniFile::SetValue(const TString SectionName,
const TString Key, TString Value) {
bool result = false;
- IniSectionData* section;
+ IniSectionData* section = NULL;
if (FMap.GetValue(SectionName, section) && section != NULL) {
result = section->SetValue(Key, Value);
@@ -189,7 +189,7 @@
bool result = false;
if (FMap.ContainsKey(SectionName) == true) {
- IniSectionData* section;
+ IniSectionData* section = NULL;
if (FMap.GetValue(SectionName, section) == true && section != NULL) {
OrderedMap<TString, TString> data = section->GetData();
diff --git a/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp b/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp
--- a/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp
+++ b/src/jdk.jpackage/unix/native/libapplauncher/PosixPlatform.cpp
@@ -95,7 +95,11 @@
}
void PosixPlatform::SetCurrentDirectory(TString Value) {
- chdir(StringToFileSystemString(Value));
+ if (chdir(StringToFileSystemString(Value))) {
+ TString message = PlatformString::Format(
+ _T("Error: Unable to chdir to %s"), Value);
+ throw Exception(message);
+ }
}
Module PosixPlatform::LoadLibrary(TString FileName) {
@@ -310,7 +314,9 @@
void PosixProcess::SetInput(TString Value) {
if (FInputHandle != 0) {
- write(FInputHandle, Value.data(), Value.size());
+ if (write(FInputHandle, Value.data(), Value.size()) == -1) {
+ printf("Error writing data\n");
+ }
}
}