Bug 568079: Cleanup of native code
* Unify pointer checkes
* Avoid using negated conditions.
* Reduce scope of local variables when possible
Change-Id: Ibacd13126351019af544f3e22513654d5ffee342
Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
diff --git a/core/org.eclipse.cdt.core.linux.aarch64/os/linux/aarch64/libspawner.so b/core/org.eclipse.cdt.core.linux.aarch64/os/linux/aarch64/libspawner.so
index a9921d7..d393021 100755
--- a/core/org.eclipse.cdt.core.linux.aarch64/os/linux/aarch64/libspawner.so
+++ b/core/org.eclipse.cdt.core.linux.aarch64/os/linux/aarch64/libspawner.so
Binary files differ
diff --git a/core/org.eclipse.cdt.core.linux.ppc64le/os/linux/ppc64le/libspawner.so b/core/org.eclipse.cdt.core.linux.ppc64le/os/linux/ppc64le/libspawner.so
index c4b0c33..fbe9987 100755
--- a/core/org.eclipse.cdt.core.linux.ppc64le/os/linux/ppc64le/libspawner.so
+++ b/core/org.eclipse.cdt.core.linux.ppc64le/os/linux/ppc64le/libspawner.so
Binary files differ
diff --git a/core/org.eclipse.cdt.core.linux.x86_64/os/linux/x86_64/libspawner.so b/core/org.eclipse.cdt.core.linux.x86_64/os/linux/x86_64/libspawner.so
index 3f888bd..207c21e 100755
--- a/core/org.eclipse.cdt.core.linux.x86_64/os/linux/x86_64/libspawner.so
+++ b/core/org.eclipse.cdt.core.linux.x86_64/os/linux/x86_64/libspawner.so
Binary files differ
diff --git a/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib b/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib
index ba694c0..5f1fc76 100755
--- a/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib
+++ b/core/org.eclipse.cdt.core.macosx/os/macosx/x86/libspawner.jnilib
Binary files differ
diff --git a/core/org.eclipse.cdt.core.macosx/os/macosx/x86_64/libspawner.jnilib b/core/org.eclipse.cdt.core.macosx/os/macosx/x86_64/libspawner.jnilib
index 7793870..9dc26b6 100755
--- a/core/org.eclipse.cdt.core.macosx/os/macosx/x86_64/libspawner.jnilib
+++ b/core/org.eclipse.cdt.core.macosx/os/macosx/x86_64/libspawner.jnilib
Binary files differ
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/exec_pty.c b/core/org.eclipse.cdt.core.native/native_src/unix/exec_pty.c
index de5b86a..fb66973 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/exec_pty.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/exec_pty.c
@@ -65,7 +65,7 @@
chdir(dirpath);
- if (channels != NULL) {
+ if (channels) {
int fds;
if (!console && setsid() < 0) {
@@ -116,10 +116,10 @@
}
}
- if (envp[0] == NULL) {
- execv(full_path, argv);
- } else {
+ if (envp && envp[0]) {
execve(full_path, argv, envp);
+ } else {
+ execv(full_path, argv);
}
_exit(127);
@@ -128,7 +128,7 @@
if (console) {
set_noecho(fdm);
}
- if (channels != NULL) {
+ if (channels) {
channels[0] = fdm; /* Input Stream. */
channels[1] = fdm; /* Output Stream. */
if (console) {
@@ -173,10 +173,10 @@
} else {
fputs("foo\n", app_stdin);
fputs("bar\n", app_stdin);
- while (fgets(buffer, sizeof buffer, app_stdout) != NULL) {
+ while (fgets(buffer, sizeof buffer, app_stdout)) {
fprintf(stdout, "STDOUT: %s\n", buffer);
}
- while (fgets(buffer, sizeof buffer, app_stderr) != NULL) {
+ while (fgets(buffer, sizeof buffer, app_stderr)) {
fprintf(stdout, "STDERR: %s\n", buffer);
}
}
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/exec_unix.c b/core/org.eclipse.cdt.core.native/native_src/unix/exec_unix.c
index 5f388a8..e393cff 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/exec_unix.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/exec_unix.c
@@ -43,7 +43,7 @@
/*
* Make sure we can create our pipes before forking.
*/
- if (channels != NULL) {
+ if (channels) {
if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
fprintf(stderr, "%s(%d): returning due to error.\n", __func__, __LINE__);
free(full_path);
@@ -60,7 +60,7 @@
} else if (childpid == 0) { /* child */
chdir(dirpath);
- if (channels != NULL) {
+ if (channels) {
/* Close the write end of pipe0 */
if (close(pipe0[1]) == -1) {
perror("close(pipe0[1])");
@@ -94,16 +94,16 @@
setpgid(getpid(), getpid());
- if (envp[0] == NULL) {
- execv(full_path, argv);
- } else {
+ if (envp && envp[0]) {
execve(full_path, argv, envp);
+ } else {
+ execv(full_path, argv);
}
_exit(127);
} else if (childpid != 0) { /* parent */
- if (channels != NULL) {
+ if (channels) {
/* close the read end of pipe1 */
if (close(pipe0[0]) == -1) {
perror("close(pipe0[0])");
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/io.c b/core/org.eclipse.cdt.core.native/native_src/unix/io.c
index 4805e9a..b29c435 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/io.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/io.c
@@ -24,7 +24,7 @@
static void ThrowByName(JNIEnv *env, const char *name, const char *msg) {
jclass cls = (*env)->FindClass(env, name);
- if (cls != 0) { /* Otherwise an exception has already been thrown */
+ if (cls) { /* Otherwise an exception has already been thrown */
(*env)->ThrowNew(env, cls, msg);
}
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/pfind.c b/core/org.eclipse.cdt.core.native/native_src/unix/pfind.c
index fbe3b73..bf96c88 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/pfind.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/pfind.c
@@ -33,12 +33,11 @@
const int path_def_len = 5; /* strlen(PATH_DEF); */
char *path_val(char *const envp[]) {
- int i;
- if (envp == NULL || envp[0] == NULL) {
+ if (!envp || !envp[0]) {
return getenv("PATH");
}
- for (i = 0; envp[i] != NULL; i++) {
+ for (int i = 0; envp[i]; i++) {
char *p = envp[i];
if (!strncmp(PATH_DEF, p, path_def_len)) {
return p + path_def_len;
@@ -56,7 +55,7 @@
struct stat sb;
/* Sanity check. */
- if (name == NULL) {
+ if (!name) {
fprintf(stderr, "pfind(): Null argument.\n");
return NULL;
}
@@ -72,7 +71,7 @@
/* Search in the PATH environment. */
path = path_val(envp);
- if (path == NULL || strlen(path) <= 0) {
+ if (!path || strlen(path) <= 0) {
fprintf(stderr, "Unable to get $PATH.\n");
return NULL;
}
@@ -81,7 +80,7 @@
path = strdup(path);
tok = strtok_r(path, ":", &sp);
- while (tok != NULL) {
+ while (tok) {
snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
if (stat(fullpath, &sb) == 0 && S_ISREG(sb.st_mode)) { /* fullpath is a file */
@@ -100,15 +99,12 @@
#ifdef BUILD_WITH_MAIN
int main(int argc, char **argv) {
- int i;
- char *fullpath;
-
- for (i = 1; i < argc; i++) {
- fullpath = pfind(argv[i], NULL);
- if (fullpath == NULL) {
- printf("Unable to find %s in $PATH.\n", argv[i]);
- } else {
+ for (int i = 1; i < argc; i++) {
+ char *fullpath = pfind(argv[i], NULL);
+ if (fullpath) {
printf("Found %s @ %s.\n", argv[i], fullpath);
+ } else {
+ printf("Unable to find %s in $PATH.\n", argv[i]);
}
}
}
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/pty.c b/core/org.eclipse.cdt.core.native/native_src/unix/pty.c
index 8ce91ee..a080062 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/pty.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/pty.c
@@ -42,7 +42,7 @@
/* Set the master fd. */
fid = (*env)->GetFieldID(env, cls, "master", "I");
- if (fid == NULL) {
+ if (!fid) {
return NULL;
}
(*env)->SetIntField(env, jobj, fid, (jint)master);
diff --git a/core/org.eclipse.cdt.core.native/native_src/unix/spawner.c b/core/org.eclipse.cdt.core.native/native_src/unix/spawner.c
index c02c8d2..a092368 100644
--- a/core/org.eclipse.cdt.core.native/native_src/unix/spawner.c
+++ b/core/org.eclipse.cdt.core.native/native_src/unix/spawner.c
@@ -102,17 +102,17 @@
int fd[3];
pid_t pid = -1;
- if (jchannels == NULL) {
+ if (!jchannels) {
goto bail_out;
}
cmd = alloc_c_array(env, jcmd);
- if (cmd == NULL) {
+ if (!cmd) {
goto bail_out;
}
envp = alloc_c_array(env, jenv);
- if (envp == NULL) {
+ if (!envp) {
goto bail_out;
}
@@ -151,12 +151,12 @@
pid_t pid = -1;
cmd = alloc_c_array(env, jcmd);
- if (cmd == NULL) {
+ if (!cmd) {
goto bail_out;
}
envp = alloc_c_array(env, jenv);
- if (envp == NULL) {
+ if (!envp) {
goto bail_out;
}
@@ -189,7 +189,7 @@
jclass channelClass = NULL;
jmethodID channelConstructor = NULL;
- if (jchannels == NULL) {
+ if (!jchannels) {
goto bail_out;
}
@@ -199,17 +199,17 @@
}
channelConstructor = (*env)->GetMethodID(env, channelClass, "<init>", "(I)V");
- if (channelConstructor == 0) {
+ if (!channelConstructor) {
goto bail_out;
}
cmd = alloc_c_array(env, jcmd);
- if (cmd == NULL) {
+ if (!cmd) {
goto bail_out;
}
envp = alloc_c_array(env, jenv);
- if (envp == NULL) {
+ if (!envp) {
goto bail_out;
}
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/Win32ProcessEx.c b/core/org.eclipse.cdt.core.native/native_src/win/Win32ProcessEx.c
index 1ddf55c..38959c9 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/Win32ProcessEx.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/Win32ProcessEx.c
@@ -121,10 +121,10 @@
size = requiredLength;
}
*ptr = (wchar_t *)realloc(*ptr, size * sizeof(wchar_t));
- if (NULL == *ptr) {
- *psize = 0;
- } else {
+ if (*ptr) {
*psize = size;
+ } else {
+ *psize = 0;
}
}
}
@@ -147,7 +147,6 @@
wchar_t *szEnvBlock = NULL;
jsize nCmdTokens = 0;
jsize nEnvVars = 0;
- int i;
DWORD pid = GetCurrentProcessId();
int nPos;
pProcInfo_t pCurProcInfo;
@@ -168,19 +167,19 @@
jclass channelClass = NULL;
jmethodID channelConstructor = NULL;
- if (channels == NULL) {
+ if (!channels) {
ThrowByName(env, "java/io/IOException", "Channels can't be null");
return 0;
}
channelClass = (*env)->FindClass(env, "org/eclipse/cdt/utils/spawner/Spawner$WinChannel");
- if (channelClass == 0) {
+ if (!channelClass) {
ThrowByName(env, "java/io/IOException", "Unable to find channel class");
return 0;
}
channelConstructor = (*env)->GetMethodID(env, channelClass, "<init>", "(J)V");
- if (channelConstructor == 0) {
+ if (!channelConstructor) {
ThrowByName(env, "java/io/IOException", "Unable to find channel constructor");
return 0;
}
@@ -236,7 +235,7 @@
pCurProcInfo = createProcInfo();
- if (NULL == pCurProcInfo) {
+ if (!pCurProcInfo) {
ThrowByName(env, "java/io/IOException", "Too many processes");
return 0;
}
@@ -252,7 +251,7 @@
nLocalCounter);
pCurProcInfo->eventBreak = CreateEventW(NULL, FALSE, FALSE, eventBreakName);
- if (NULL == pCurProcInfo->eventBreak || GetLastError() == ERROR_ALREADY_EXISTS) {
+ if (!pCurProcInfo->eventBreak || GetLastError() == ERROR_ALREADY_EXISTS) {
ThrowByName(env, "java/io/IOException", "Cannot create event");
return 0;
}
@@ -266,19 +265,19 @@
nPos = wcslen(szCmdLine);
// Prepare command line
- for (i = 0; i < nCmdTokens; ++i) {
+ for (int i = 0; i < nCmdTokens; ++i) {
jstring item = (jstring)(*env)->GetObjectArrayElement(env, cmdarray, i);
jsize len = (*env)->GetStringLength(env, item);
int nCpyLen;
const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, item, 0);
- if (NULL != str) {
+ if (str) {
int requiredSize = nPos + len + 2;
if (requiredSize > 32 * 1024) {
ThrowByName(env, "java/io/IOException", "Command line too long");
return 0;
}
ensureSize(&szCmdLine, &nCmdLineLength, requiredSize);
- if (NULL == szCmdLine) {
+ if (!szCmdLine) {
ThrowByName(env, "java/io/IOException", "Not enough memory");
return 0;
}
@@ -303,15 +302,15 @@
if (nEnvVars > 0) {
nPos = 0;
szEnvBlock = (wchar_t *)malloc(nBlkSize * sizeof(wchar_t));
- for (i = 0; i < nEnvVars; ++i) {
+ for (int i = 0; i < nEnvVars; ++i) {
jstring item = (jstring)(*env)->GetObjectArrayElement(env, envp, i);
jsize len = (*env)->GetStringLength(env, item);
const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, item, 0);
- if (NULL != str) {
+ if (str) {
while ((nBlkSize - nPos) <= (len + 2)) { // +2 for two '\0'
nBlkSize += MAX_ENV_SIZE;
szEnvBlock = (wchar_t *)realloc(szEnvBlock, nBlkSize * sizeof(wchar_t));
- if (NULL == szEnvBlock) {
+ if (!szEnvBlock) {
ThrowByName(env, "java/io/IOException", "Not enough memory");
return 0;
}
@@ -332,11 +331,11 @@
szEnvBlock[nPos] = _T('\0');
}
- if (dir != 0) {
- const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, dir, 0);
- if (NULL != str) {
- cwd = wcsdup(str);
- (*env)->ReleaseStringChars(env, dir, (const jchar *)str);
+ if (dir) {
+ const jchar *str = (*env)->GetStringChars(env, dir, NULL);
+ if (str) {
+ cwd = wcsdup((const wchar_t *)str);
+ (*env)->ReleaseStringChars(env, dir, str);
}
}
@@ -482,14 +481,14 @@
jsize len = (*env)->GetStringLength(env, item);
int nCpyLen;
const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, item, 0);
- if (NULL != str) {
+ if (str) {
int requiredSize = nPos + len + 2;
if (requiredSize > 32 * 1024) {
ThrowByName(env, "java/io/IOException", "Command line too long");
return 0;
}
ensureSize(&szCmdLine, &nCmdLineLength, requiredSize);
- if (NULL == szCmdLine) {
+ if (!szCmdLine) {
ThrowByName(env, "java/io/IOException", "Not enough memory");
return 0;
}
@@ -515,11 +514,11 @@
jstring item = (jstring)(*env)->GetObjectArrayElement(env, envp, i);
jsize len = (*env)->GetStringLength(env, item);
const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, item, 0);
- if (NULL != str) {
+ if (str) {
while ((nBlkSize - nPos) <= (len + 2)) { // +2 for two '\0'
nBlkSize += MAX_ENV_SIZE;
szEnvBlock = (wchar_t *)realloc(szEnvBlock, nBlkSize * sizeof(wchar_t));
- if (NULL == szEnvBlock) {
+ if (!szEnvBlock) {
ThrowByName(env, "java/io/Exception", "Not enough memory");
return 0;
}
@@ -535,11 +534,11 @@
envBlk = szEnvBlock;
}
- if (dir != 0) {
- const wchar_t *str = (const wchar_t *)(*env)->GetStringChars(env, dir, 0);
- if (NULL != str) {
- cwd = wcsdup(str);
- (*env)->ReleaseStringChars(env, dir, (const jchar *)str);
+ if (dir) {
+ const jchar *str = (*env)->GetStringChars(env, dir, NULL);
+ if (str) {
+ cwd = wcsdup((const wchar_t *)str);
+ (*env)->ReleaseStringChars(env, dir, str);
}
}
@@ -599,7 +598,7 @@
HANDLE hProc;
pProcInfo_t pCurProcInfo = findProcInfo(uid);
- if (NULL == pCurProcInfo) {
+ if (!pCurProcInfo) {
if (SIG_INT == signal) { // Try another way
return interruptProcess(uid);
}
@@ -612,7 +611,7 @@
hProc = OpenProcess(SYNCHRONIZE, 0, pCurProcInfo->pid);
- if (NULL == hProc) {
+ if (!hProc) {
return -1;
}
@@ -679,13 +678,13 @@
HANDLE hProc;
pProcInfo_t pCurProcInfo = findProcInfo(uid);
- if (NULL == pCurProcInfo) {
+ if (!pCurProcInfo) {
return -1;
}
hProc = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, 0, pCurProcInfo->pid);
- if (NULL == hProc) {
+ if (!hProc) {
return -1;
}
@@ -713,7 +712,7 @@
void ThrowByName(JNIEnv *env, const char *name, const char *msg) {
jclass cls = (*env)->FindClass(env, name);
- if (cls != 0) { /* Otherwise an exception has already been thrown */
+ if (cls) { /* Otherwise an exception has already been thrown */
(*env)->ThrowNew(env, cls, msg);
}
@@ -727,17 +726,16 @@
// Return : pointer to the process descriptor
/////////////////////////////////////////////////////////////////////////////////////
pProcInfo_t createProcInfo() {
- int i;
pProcInfo_t p = NULL;
EnterCriticalSection(&cs);
- if (NULL == pInfo) {
+ if (!pInfo) {
pInfo = (pProcInfo_t)malloc(sizeof(procInfo_t) * MAX_PROCS);
ZeroMemory(pInfo, sizeof(procInfo_t) * MAX_PROCS);
}
- for (i = 0; i < MAX_PROCS; ++i) {
+ for (int i = 0; i < MAX_PROCS; ++i) {
if (pInfo[i].pid == 0) {
pInfo[i].pid = -1;
pInfo[i].uid = ++procCounter;
@@ -757,20 +755,15 @@
// Return : pointer to the process descriptor
/////////////////////////////////////////////////////////////////////////////////////
pProcInfo_t findProcInfo(int uid) {
- int i;
- pProcInfo_t p = NULL;
- if (NULL == pInfo) {
- return NULL;
- }
-
- for (i = 0; i < MAX_PROCS; ++i) {
- if (pInfo[i].uid == uid) {
- p = pInfo + i;
- break;
+ if (pInfo) {
+ for (int i = 0; i < MAX_PROCS; ++i) {
+ if (pInfo[i].uid == uid) {
+ return pInfo + i;
+ }
}
}
- return p;
+ return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////
@@ -813,12 +806,11 @@
/////////////////////////////////////////////////////////////////////////////////////
void _cdecl waitProcTermination(void *pv) {
PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)pv;
- int i;
// wait for process termination
WaitForSingleObject(pi->hProcess, INFINITE);
- for (i = 0; i < MAX_PROCS; ++i) {
+ for (int i = 0; i < MAX_PROCS; i++) {
if (pInfo[i].pid == pi->dwProcessId) {
cleanUpProcBlock(pInfo + i);
if (isTraceEnabled(CDT_TRACE_MONITOR)) {
@@ -841,14 +833,10 @@
// Return :number of bytes used in target, or -1 in case of error
/////////////////////////////////////////////////////////////////////////////////////
int copyTo(wchar_t *target, const wchar_t *source, int cpyLength, int availSpace) {
- BOOL bSlash = FALSE;
+ bool bSlash = false;
int i = 0, j = 0;
-#define QUOTATION_DO 0
-#define QUOTATION_DONE 1
-#define QUOTATION_NONE 2
-
- int nQuotationMode = 0;
+ enum { QUOTATION_DO, QUOTATION_DONE, QUOTATION_NONE } nQuotationMode = QUOTATION_DO;
if (availSpace <= cpyLength) { // = to reserve space for final '\0'
return -1;
@@ -856,19 +844,19 @@
if ((_T('\"') == *source) && (_T('\"') == *(source + cpyLength - 1))) {
nQuotationMode = QUOTATION_DONE;
- } else if (wcschr(source, _T(' ')) == NULL) {
- // No reason to quote term because it doesn't have embedded spaces
- nQuotationMode = QUOTATION_NONE;
- } else {
+ } else if (wcschr(source, _T(' '))) {
// Needs to be quoted
nQuotationMode = QUOTATION_DO;
*target = _T('\"');
++j;
+ } else {
+ // No reason to quote term because it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
}
for (; i < cpyLength; ++i, ++j) {
if (source[i] == _T('\\')) {
- bSlash = TRUE;
+ bSlash = true;
} else {
// Don't escape embracing quotation marks
if ((source[i] == _T('\"')) &&
@@ -881,7 +869,7 @@
++j;
}
}
- bSlash = FALSE;
+ bSlash = false;
}
if (j == availSpace) {
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/iostream.c b/core/org.eclipse.cdt.core.native/native_src/win/iostream.c
index c63d2cf..7415961 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/iostream.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/iostream.c
@@ -30,19 +30,19 @@
#define BUFF_SIZE (1024)
static HANDLE channelToHandle(JNIEnv *env, jobject channel) {
- if (channel == 0) {
+ if (!channel) {
ThrowByName(env, "java/io/IOException", "Invalid channel object");
return NULL;
}
jclass cls = (*env)->GetObjectClass(env, channel);
- if (cls == NULL) {
+ if (!cls) {
ThrowByName(env, "java/io/IOException", "Unable to get channel class");
return NULL;
}
jfieldID fid = (*env)->GetFieldID(env, cls, "handle", "J");
- if (fid == NULL) {
+ if (!fid) {
ThrowByName(env, "java/io/IOException", "Unable to find handle");
return NULL;
}
@@ -69,7 +69,7 @@
TRUE, // initial state = signaled
NULL); // unnamed event object
- if (NULL == overlapped.hEvent) {
+ if (!overlapped.hEvent) {
char *lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/pty.cpp b/core/org.eclipse.cdt.core.native/native_src/win/pty.cpp
index 8824458..a974f68 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/pty.cpp
+++ b/core/org.eclipse.cdt.core.native/native_src/win/pty.cpp
@@ -39,7 +39,7 @@
/* Open new winpty handle */
winpty_t *winpty = winpty_open(80, 40);
- if (winpty == NULL) {
+ if (!winpty) {
return NULL;
}
@@ -67,7 +67,7 @@
/* Set the master fd. */
fid = env->GetFieldID(cls, "master", "I");
- if (fid == NULL) {
+ if (!fid) {
return NULL;
}
env->SetIntField(jobj, fid, (jint)master);
@@ -87,7 +87,7 @@
fd2pty_Iter = fd2pty.find(fd);
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
- if (winpty != NULL) {
+ if (winpty) {
return winpty_set_size(winpty, width, height);
}
}
@@ -106,7 +106,7 @@
fd2pty_Iter = fd2pty.find(fd);
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
- if (winpty != NULL) {
+ if (winpty) {
/* Get the pipe handle */
HANDLE handle = winpty_get_data_pipe(winpty);
@@ -159,7 +159,7 @@
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
fd2pty.erase(fd2pty_Iter);
- if (winpty != NULL) {
+ if (winpty) {
winpty_close(winpty);
winpty = NULL;
}
@@ -179,7 +179,7 @@
fd2pty_Iter = fd2pty.find(fd);
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
- if (winpty != NULL) {
+ if (winpty) {
/* Get the pipe handle */
HANDLE handle = winpty_get_data_pipe(winpty);
@@ -218,7 +218,7 @@
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
fd2pty.erase(fd2pty_Iter);
- if (winpty != NULL) {
+ if (winpty) {
winpty_close(winpty);
winpty = NULL;
}
@@ -253,7 +253,7 @@
result.push_back(L' ');
}
const wchar_t *arg = argv[argIndex].c_str();
- const bool quote = wcschr(arg, L' ') != NULL || wcschr(arg, L'\t') != NULL || *arg == L'\0';
+ const bool quote = wcschr(arg, L' ') || wcschr(arg, L'\t') || *arg == L'\0';
if (quote) {
result.push_back(L'\"');
}
@@ -292,11 +292,10 @@
int pid = -1;
- int i;
jint argc = env->GetArrayLength(jcmd);
jint envc = env->GetArrayLength(jenv);
- if (jchannels == NULL || env->GetArrayLength(jchannels) != 3) {
+ if (!jchannels || env->GetArrayLength(jchannels) != 3) {
goto bail_out;
}
@@ -304,10 +303,10 @@
fd2pty_Iter = fd2pty.find(fd);
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
- if (winpty != NULL) {
+ if (winpty) {
std::vector<std::wstring> argVector;
- for (i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; i++) {
jstring j_str = (jstring)env->GetObjectArrayElement(jcmd, i);
const wchar_t *w_str = (const wchar_t *)env->GetStringChars(j_str, NULL);
if (i == 0) {
@@ -321,7 +320,7 @@
std::wstring envp;
- for (i = 0; i < envc; i++) {
+ for (int i = 0; i < envc; i++) {
jstring j_str = (jstring)env->GetObjectArrayElement(jenv, i);
const wchar_t *w_str = (const wchar_t *)env->GetStringChars(j_str, NULL);
envp.append(w_str);
@@ -361,7 +360,7 @@
fd2pty_Iter = fd2pty.find(fd);
if (fd2pty_Iter != fd2pty.end()) {
winpty_t *winpty = fd2pty_Iter->second;
- if (winpty != NULL) {
+ if (winpty) {
HANDLE handle = winpty_get_data_pipe(winpty);
BOOL success;
do {
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/raise.c b/core/org.eclipse.cdt.core.native/native_src/win/raise.c
index 7efd2c6..dc55814 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/raise.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/raise.c
@@ -74,7 +74,7 @@
int interruptProcess(int pid) {
// See if DebugBreakProcess is available (XP and beyond)
HMODULE hmod = LoadLibrary(L"Kernel32.dll");
- if (hmod != NULL) {
+ if (hmod) {
BOOL success = FALSE;
FARPROC procaddr = GetProcAddress(hmod, "DebugBreakProcess");
if (procaddr != NULL) {
@@ -103,7 +103,7 @@
// Find console
EnumWindows(find_child_console, (LPARAM)pid);
- if (NULL != consoleHWND) { // Yes, we found out it
+ if (consoleHWND) { // Yes, we found out it
// We are going to switch focus to console,
// send Ctrl-C and then restore focus
BYTE control_scan_code = (BYTE)MapVirtualKey(VK_CONTROL, 0);
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/spawner.c b/core/org.eclipse.cdt.core.native/native_src/win/spawner.c
index 81fc68b..adf5ccc 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/spawner.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/spawner.c
@@ -36,7 +36,7 @@
InitializeCriticalSection(&cs);
GetModuleFileNameW(hModule, path, MAX_PATH);
p = wcsrchr(path, _T('\\'));
- if (NULL != p) {
+ if (p) {
*(p + 1) = _T('\0');
} else {
wcscat(path, L"\\");
diff --git a/core/org.eclipse.cdt.core.native/native_src/win/starter.c b/core/org.eclipse.cdt.core.native/native_src/win/starter.c
index d6b7384..85a9748 100644
--- a/core/org.eclipse.cdt.core.native/native_src/win/starter.c
+++ b/core/org.eclipse.cdt.core.native/native_src/win/starter.c
@@ -66,7 +66,7 @@
bool isCygwin(HANDLE process) {
// Have we checked before?
- if (cygwinBin != NULL || !_isCygwin) {
+ if (cygwinBin || !_isCygwin) {
return _isCygwin;
}
@@ -128,10 +128,10 @@
size = requiredLength;
}
*ptr = (wchar_t *)realloc(*ptr, size * sizeof(wchar_t));
- if (NULL == *ptr) {
- *psize = 0;
- } else {
+ if (*ptr) {
*psize = size;
+ } else {
+ *psize = 0;
}
}
}
@@ -164,7 +164,7 @@
return 0;
}
ensureSize(&szCmdLine, &nCmdLineLength, requiredSize);
- if (NULL == szCmdLine) {
+ if (!szCmdLine) {
if (isTraceEnabled(CDT_TRACE_MONITOR)) {
cdtTrace(L"Not enough memory to build cmd line!\n");
}
@@ -255,10 +255,7 @@
if (isTraceEnabled(CDT_TRACE_MONITOR_DETAILS)) {
wchar_t *lpvEnv = GetEnvironmentStringsW();
- // If the returned pointer is NULL, exit.
- if (lpvEnv == NULL) {
- cdtTrace(L"Cannot Read Environment\n");
- } else {
+ if (lpvEnv) {
// Variable strings are separated by NULL byte, and the block is
// terminated by a NULL byte.
@@ -268,6 +265,9 @@
}
FreeEnvironmentStringsW(lpvEnv);
+ } else {
+ // If the returned pointer is NULL, exit.
+ cdtTrace(L"Cannot Read Environment\n");
}
}
if (isTraceEnabled(CDT_TRACE_MONITOR)) {
@@ -275,7 +275,7 @@
}
// Create job object
HANDLE hJob = CreateJobObject(NULL, NULL);
- if (hJob != NULL) {
+ if (hJob) {
// Configure job to
// - terminate all associated processes when the last handle to it is closed
// - allow child processes to break away from the job.
@@ -315,7 +315,7 @@
CloseHandle(pi.hThread);
h[1] = pi.hProcess;
- if (NULL != hJob) {
+ if (hJob) {
if (!AssignProcessToJobObject(hJob, pi.hProcess)) {
if (isTraceEnabled(CDT_TRACE_MONITOR)) {
cdtTrace(L"Cannot assign process %i to a job\n", pi.dwProcessId);
@@ -383,7 +383,7 @@
SetEvent(waitEvent);
- if (NULL != hJob) {
+ if (hJob) {
if (!TerminateJobObject(hJob, (DWORD)-1)) {
if (isTraceEnabled(CDT_TRACE_MONITOR)) {
cdtTrace(L"Cannot terminate job\n");
@@ -433,14 +433,11 @@
// Return :number of bytes used in target, or -1 in case of error
/////////////////////////////////////////////////////////////////////////////////////
int copyTo(wchar_t *target, const wchar_t *source, int cpyLength, int availSpace) {
- BOOL bSlash = FALSE;
+ bool bSlash = false;
int i = 0, j = 0;
-#define QUOTATION_DO 0
-#define QUOTATION_DONE 1
-#define QUOTATION_NONE 2
+ enum { QUOTATION_DO, QUOTATION_DONE, QUOTATION_NONE } nQuotationMode = QUOTATION_DO;
- int nQuotationMode = 0;
if (availSpace <= cpyLength) { // = to reserve space for '\0'
return -1;
}
@@ -448,19 +445,19 @@
if ((_T('\"') == *source) && (_T('\"') == *(source + cpyLength - 1))) {
// Already done
nQuotationMode = QUOTATION_DONE;
- } else if (wcschr(source, _T(' ')) == NULL) {
- // No reason to quotate term becase it doesn't have embedded spaces
- nQuotationMode = QUOTATION_NONE;
- } else {
+ } else if (wcschr(source, _T(' '))) {
// Needs to be quotated
nQuotationMode = QUOTATION_DO;
*target = _T('\"');
++j;
+ } else {
+ // No reason to quotate term because it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
}
for (; i < cpyLength; ++i, ++j) {
if (source[i] == _T('\\')) {
- bSlash = TRUE;
+ bSlash = true;
} else {
// Don't escape embracing quotation marks
if ((source[i] == _T('\"')) &&
@@ -472,9 +469,9 @@
target[j] = _T('\\');
++j;
}
- bSlash = FALSE;
+ bSlash = false;
} else {
- bSlash = FALSE;
+ bSlash = false;
}
}
diff --git a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/pty.dll b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/pty.dll
index b74a2eb..5751bb1 100755
--- a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/pty.dll
+++ b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/pty.dll
Binary files differ
diff --git a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/spawner.dll b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/spawner.dll
index 4ba9c3c..ae55557 100755
--- a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/spawner.dll
+++ b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/spawner.dll
Binary files differ
diff --git a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/starter.exe b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/starter.exe
index 700d95a..d86256e 100755
--- a/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/starter.exe
+++ b/core/org.eclipse.cdt.core.win32.x86_64/os/win32/x86_64/starter.exe
Binary files differ