summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorNicola Ruggero <nicola@nxnt.org>2010-11-03 16:59:26 +0100
committerNicola Ruggero <nicola@nxnt.org>2010-11-03 16:59:26 +0100
commit4cf06dbbcb8522be5fa069976c8f361fc874039f (patch)
tree6e074a89c4edadf9a75d648d1f9daf36079c03aa /common
parent104f762e5d3dcd659415632f442e745cef5a3bf2 (diff)
downloadxrdp-proprietary-4cf06dbbcb8522be5fa069976c8f361fc874039f.tar.gz
xrdp-proprietary-4cf06dbbcb8522be5fa069976c8f361fc874039f.zip
Major code cleanup:
- Initialized and zeroed out local variables - Check for some null pointers - Fixed some typos - Other minor changes (beautify, etc.)
Diffstat (limited to 'common')
-rw-r--r--common/defines.h2
-rw-r--r--common/os_calls.c86
-rw-r--r--common/os_calls.h4
-rw-r--r--common/thread_calls.c31
-rw-r--r--common/trans.c51
5 files changed, 113 insertions, 61 deletions
diff --git a/common/defines.h b/common/defines.h
index 2dbb1893..a6f6e303 100644
--- a/common/defines.h
+++ b/common/defines.h
@@ -20,7 +20,7 @@
*/
-#if !defined(DEFINES_H)
+#ifndef DEFINES_H
#define DEFINES_H
/* check for debug */
diff --git a/common/os_calls.c b/common/os_calls.c
index 913c4296..617f3d60 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -616,8 +616,11 @@ g_tcp_select(int sck1, int sck2)
{
fd_set rfds;
struct timeval time;
- int max;
- int rv;
+ int max = 0;
+ int rv = 0;
+
+ g_memset(&rfds,0,sizeof(fd_set));
+ g_memset(&time,0,sizeof(struct timeval));
time.tv_sec = 0;
time.tv_usec = 0;
@@ -668,9 +671,11 @@ g_create_wait_obj(char* name)
#else
tbus obj;
struct sockaddr_un sa;
- int len;
- int sck;
- int i;
+ size_t len = 0;
+ tbus sck = -1;
+ int i = 0;
+
+ g_memset(&sa,0,sizeof(struct sockaddr_un));
sck = socket(PF_UNIX, SOCK_DGRAM, 0);
if (sck < 0)
@@ -713,7 +718,9 @@ g_create_wait_obj_from_socket(tbus socket, int write)
#ifdef _WIN32
/* Create and return corresponding event handle for WaitForMultipleObjets */
WSAEVENT event;
- long lnetevent;
+ long lnetevent = 0;
+
+ g_memset(&event,0,sizeof(WSAEVENT));
event = WSACreateEvent();
lnetevent = (write ? FD_WRITE : FD_READ) | FD_CLOSE;
@@ -906,15 +913,20 @@ g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
fd_set rfds;
fd_set wfds;
struct timeval time;
- struct timeval* ptime;
- int i;
- int max;
- int sck;
+ struct timeval* ptime = (struct timeval *)NULL;
+ int i = 0;
+ int res = 0;
+ int max = 0;
+ int sck = 0;
+
+ g_memset(&rfds,0,sizeof(fd_set));
+ g_memset(&wfds,0,sizeof(fd_set));
+ g_memset(&time,0,sizeof(struct timeval));
max = 0;
if (mstimeout < 1)
{
- ptime = 0;
+ ptime = (struct timeval *)NULL;
}
else
{
@@ -927,23 +939,27 @@ g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount,
for (i = 0; i < rcount; i++)
{
sck = (int)(read_objs[i]);
- FD_SET(sck, &rfds);
- if (sck > max)
- {
- max = sck;
+ if (sck > 0) {
+ FD_SET(sck, &rfds);
+ if (sck > max)
+ {
+ max = sck;
+ }
}
}
for (i = 0; i < wcount; i++)
{
sck = (int)(write_objs[i]);
- FD_SET(sck, &wfds);
- if (sck > max)
- {
- max = sck;
+ if (sck > 0) {
+ FD_SET(sck, &wfds);
+ if (sck > max)
+ {
+ max = sck;
+ }
}
}
- i = select(max + 1, &rfds, &wfds, 0, ptime);
- if (i < 0)
+ res = select(max + 1, &rfds, &wfds, 0, ptime);
+ if (res < 0)
{
/* these are not really errors */
if ((errno == EAGAIN) ||
@@ -1296,7 +1312,7 @@ g_file_get_size(const char* filename)
int APP_CC
g_strlen(const char* text)
{
- if (text == 0)
+ if (text == NULL)
{
return 0;
}
@@ -1367,7 +1383,9 @@ g_strdup(const char* in)
}
len = g_strlen(in);
p = (char*)g_malloc(len + 1, 0);
- g_strcpy(p, in);
+ if (p != NULL) {
+ g_strcpy(p, in);
+ }
return p;
}
@@ -1916,14 +1934,18 @@ g_waitpid(int pid)
#if defined(_WIN32)
return 0;
#else
- int rv;
-
- rv = waitpid(pid, 0, 0);
- if (rv == -1)
- {
- if (errno == EINTR) /* signal occurred */
+ int rv = 0;
+ if (pid < 0) {
+ rv = -1;
+ }
+ else {
+ rv = waitpid(pid, 0, 0);
+ if (rv == -1)
{
- rv = 0;
+ if (errno == EINTR) /* signal occurred */
+ {
+ rv = 0;
+ }
}
}
return rv;
@@ -2119,8 +2141,8 @@ g_time2(void)
return (int)GetTickCount();
#else
struct tms tm;
- clock_t num_ticks;
-
+ clock_t num_ticks = 0;
+ g_memset(&tm,0,sizeof(struct tms));
num_ticks = times(&tm);
return (int)(num_ticks * 10);
#endif
diff --git a/common/os_calls.h b/common/os_calls.h
index 333c0f29..377b1174 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -25,6 +25,10 @@
#if !defined(OS_CALLS_H)
#define OS_CALLS_H
+#ifndef NULL
+#define NULL 0
+#endif
+
#include "arch.h"
void APP_CC
diff --git a/common/thread_calls.c b/common/thread_calls.c
index e0d7f1e8..80856fd8 100644
--- a/common/thread_calls.c
+++ b/common/thread_calls.c
@@ -33,15 +33,16 @@
#include "thread_calls.h"
#include "os_calls.h"
+
/*****************************************************************************/
/* returns error */
#if defined(_WIN32)
int APP_CC
tc_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg)
{
- DWORD thread_id;
- HANDLE thread;
- int rv;
+ int rv = 0;
+ DWORD thread_id = 0;
+ HANDLE thread = (HANDLE)0;
/* CreateThread returns handle or zero on error */
thread = CreateThread(0, 0, start_routine, arg, 0, &thread_id);
@@ -51,14 +52,18 @@ tc_thread_create(unsigned long (__stdcall * start_routine)(void*), void* arg)
}
#else
int APP_CC
-tc_thread_create(void* (* start_routine)(void*), void* arg)
+tc_thread_create(void* (* start_routine)(void *), void* arg)
{
- pthread_t thread;
- int rv;
+ int rv = 0;
+ pthread_t thread = (pthread_t)0;
+
+ g_memset(&thread, 0x00, sizeof(pthread_t));
/* pthread_create returns error */
rv = pthread_create(&thread, 0, start_routine, arg);
- pthread_detach(thread);
+ if (!rv) {
+ rv = pthread_detach(thread);
+ }
return rv;
}
#endif
@@ -133,13 +138,15 @@ tc_mutex_lock(tbus mutex)
int APP_CC
tc_mutex_unlock(tbus mutex)
{
+ int rv = 0;
#if defined(_WIN32)
ReleaseMutex((HANDLE)mutex);
- return 0;
#else
- pthread_mutex_unlock((pthread_mutex_t*)mutex);
- return 0;
+ if (mutex != 0) {
+ rv = pthread_mutex_unlock((pthread_mutex_t *)mutex);
+ }
#endif
+ return rv;
}
/*****************************************************************************/
@@ -152,9 +159,9 @@ tc_sem_create(int init_count)
sem = CreateSemaphore(0, init_count, init_count + 10, 0);
return (tbus)sem;
#else
- sem_t* sem;
+ sem_t * sem = (sem_t *)NULL;
- sem = g_malloc(sizeof(sem_t), 0);
+ sem = (sem_t *)g_malloc(sizeof(sem_t), 0);
sem_init(sem, 0, init_count);
return (tbus)sem;
#endif
diff --git a/common/trans.c b/common/trans.c
index 37e3f211..377b90ba 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -32,14 +32,16 @@
struct trans* APP_CC
trans_create(int mode, int in_size, int out_size)
{
- struct trans* self;
+ struct trans* self = (struct trans *)NULL;
self = (struct trans*)g_malloc(sizeof(struct trans), 1);
- make_stream(self->in_s);
- init_stream(self->in_s, in_size);
- make_stream(self->out_s);
- init_stream(self->out_s, out_size);
- self->mode = mode;
+ if (self != NULL) {
+ make_stream(self->in_s);
+ init_stream(self->in_s, in_size);
+ make_stream(self->out_s);
+ init_stream(self->out_s, out_size);
+ self->mode = mode;
+ }
return self;
}
@@ -53,7 +55,10 @@ trans_delete(struct trans* self)
}
free_stream(self->in_s);
free_stream(self->out_s);
- g_tcp_close(self->sck);
+ if (self->sck > 0) {
+ g_tcp_close(self->sck);
+ }
+ self->sck = 0;
if (self->listen_filename != 0)
{
g_file_delete(self->listen_filename);
@@ -83,12 +88,12 @@ trans_get_wait_objs(struct trans* self, tbus* objs, int* count, int* timeout)
int APP_CC
trans_check_wait_objs(struct trans* self)
{
- tbus in_sck;
- struct trans* in_trans;
- int read_bytes;
- int to_read;
- int read_so_far;
- int rv;
+ tbus in_sck = (tbus)0;
+ struct trans* in_trans = (struct trans *)NULL;
+ int read_bytes = 0;
+ int to_read = 0;
+ int read_so_far = 0;
+ int rv = 0;
if (self == 0)
{
@@ -391,13 +396,27 @@ trans_listen(struct trans* self, char* port)
struct stream* APP_CC
trans_get_in_s(struct trans* self)
{
- return self->in_s;
+ struct stream * rv = (struct stream *)NULL;
+ if (self == NULL) {
+ rv = (struct stream *)NULL;
+ }
+ else {
+ rv = self->in_s;
+ }
+ return rv;
}
/*****************************************************************************/
struct stream* APP_CC
trans_get_out_s(struct trans* self, int size)
{
- init_stream(self->out_s, size);
- return self->out_s;
+ struct stream * rv = (struct stream *)NULL;
+ if (self == NULL) {
+ rv = (struct stream *)NULL;
+ }
+ else {
+ init_stream(self->out_s, size);
+ rv = self->out_s;
+ }
+ return rv;
}