summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2004-02-13 21:27:42 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2004-02-13 21:27:42 +0000
commitaee5a6384985746420fda1c07d4231c4272ae715 (patch)
treeec784f7f8aa36ef58566b8fe31c6927e52398089 /src
parentbf22966f558ca95222c94706124a3a385f5aa0bf (diff)
Removed unnecessary casts (mostly dealing with memory allocation.) I
should never have added them in the first place. They don't really buy anything, and they can hide bugs.
Diffstat (limited to 'src')
-rw-r--r--src/acl.c4
-rw-r--r--src/buffer.c8
-rw-r--r--src/child.c11
-rw-r--r--src/conns.c4
-rw-r--r--src/filter.c4
-rw-r--r--src/hashmap.c10
-rw-r--r--src/heap.c8
-rw-r--r--src/http_message.c10
-rw-r--r--src/log.c6
-rw-r--r--src/network.c18
-rw-r--r--src/reqs.c23
-rw-r--r--src/stats.c6
-rw-r--r--src/vector.c6
13 files changed, 56 insertions, 62 deletions
diff --git a/src/acl.c b/src/acl.c
index d56ac65..cbce7fe 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -1,4 +1,4 @@
-/* $Id: acl.c,v 1.17 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: acl.c,v 1.18 2004-02-13 21:27:42 rjkaes Exp $
*
* This system handles Access Control for use of this daemon. A list of
* domains, or IP addresses (including IP blocks) are stored in a list
@@ -87,7 +87,7 @@ insert_acl(char *location, acl_access_t access_type)
rev_acl_ptr = &acl_ptr->next;
acl_ptr = acl_ptr->next;
}
- new_acl_ptr = (struct acl_s*)safemalloc(sizeof(struct acl_s));
+ new_acl_ptr = safemalloc(sizeof(struct acl_s));
if (!new_acl_ptr) {
return -1;
}
diff --git a/src/buffer.c b/src/buffer.c
index db805d1..0497fbc 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,4 +1,4 @@
-/* $Id: buffer.c,v 1.23 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: buffer.c,v 1.24 2004-02-13 21:27:42 rjkaes Exp $
*
* The buffer used in each connection is a linked list of lines. As the lines
* are read in and written out the buffer expands and contracts. Basically,
@@ -60,10 +60,10 @@ makenewline(unsigned char *data, size_t length)
assert(data != NULL);
assert(length > 0);
- if (!(newline = (struct bufline_s*)safemalloc(sizeof(struct bufline_s))))
+ if (!(newline = safemalloc(sizeof(struct bufline_s))))
return NULL;
- if (!(newline->string = (unsigned char*)safemalloc(length))) {
+ if (!(newline->string = safemalloc(length))) {
safefree(newline);
return NULL;
}
@@ -104,7 +104,7 @@ new_buffer(void)
{
struct buffer_s *buffptr;
- if (!(buffptr = (struct buffer_s*)safemalloc(sizeof(struct buffer_s))))
+ if (!(buffptr = safemalloc(sizeof(struct buffer_s))))
return NULL;
/*
diff --git a/src/child.c b/src/child.c
index f7ddf23..25f87fa 100644
--- a/src/child.c
+++ b/src/child.c
@@ -1,4 +1,4 @@
-/* $Id: child.c,v 1.13 2003-08-07 15:31:20 rjkaes Exp $
+/* $Id: child.c,v 1.14 2004-02-13 21:27:42 rjkaes Exp $
*
* Handles the creation/destruction of the various children required for
* processing incoming connections.
@@ -165,7 +165,7 @@ child_main(struct child_s* ptr)
struct sockaddr *cliaddr;
socklen_t clilen;
- cliaddr = (struct sockaddr*)safemalloc(addrlen);
+ cliaddr = safemalloc(addrlen);
if (!cliaddr) {
log_message(LOG_CRIT,
"Could not allocate memory for child address.");
@@ -293,15 +293,14 @@ child_pool_create(void)
return -1;
}
- child_ptr = (struct child_s*)calloc_shared_memory(
- child_config.maxclients,
- sizeof(struct child_s));
+ child_ptr = calloc_shared_memory(child_config.maxclients,
+ sizeof(struct child_s));
if (!child_ptr) {
log_message(LOG_ERR, "Could not allocate memory for children.");
return -1;
}
- servers_waiting = (unsigned int*)malloc_shared_memory(sizeof(unsigned int));
+ servers_waiting = malloc_shared_memory(sizeof(unsigned int));
if (servers_waiting == MAP_FAILED) {
log_message(LOG_ERR, "Could not allocate memory for child counting.");
return -1;
diff --git a/src/conns.c b/src/conns.c
index 4420721..c7091a3 100644
--- a/src/conns.c
+++ b/src/conns.c
@@ -1,4 +1,4 @@
-/* $Id: conns.c,v 1.20 2004-01-26 19:11:51 rjkaes Exp $
+/* $Id: conns.c,v 1.21 2004-02-13 21:27:42 rjkaes Exp $
*
* Create and free the connection structure. One day there could be
* other connection related tasks put here, but for now the header
@@ -46,7 +46,7 @@ initialize_conn(int client_fd, const char* ipaddr, const char* string_addr)
/*
* Allocate the space for the conn_s structure itself.
*/
- connptr = (struct conn_s*)safemalloc(sizeof(struct conn_s));
+ connptr = safemalloc(sizeof(struct conn_s));
if (!connptr)
goto error_exit;
diff --git a/src/filter.c b/src/filter.c
index 99505a3..2205f6b 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -1,4 +1,4 @@
-/* $Id: filter.c,v 1.19 2003-10-17 16:11:00 rjkaes Exp $
+/* $Id: filter.c,v 1.20 2004-02-13 21:27:42 rjkaes Exp $
*
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
* Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu)
@@ -106,7 +106,7 @@ filter_init(void)
}
p->pat = safestrdup(s);
- p->cpat = (regex_t*)safemalloc(sizeof(regex_t));
+ p->cpat = safemalloc(sizeof(regex_t));
if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {
fprintf(stderr, "Bad regex in %s: %s\n",
config.filter, p->pat);
diff --git a/src/hashmap.c b/src/hashmap.c
index 1c32f8a..f1806af 100644
--- a/src/hashmap.c
+++ b/src/hashmap.c
@@ -1,4 +1,4 @@
-/* $Id: hashmap.c,v 1.13 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: hashmap.c,v 1.14 2004-02-13 21:27:42 rjkaes Exp $
*
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
@@ -97,14 +97,12 @@ hashmap_create(unsigned int nbuckets)
if (nbuckets == 0)
return NULL;
- ptr = (struct hashmap_s*)safecalloc(1, sizeof(struct hashmap_s));
+ ptr = safecalloc(1, sizeof(struct hashmap_s));
if (!ptr)
return NULL;
ptr->size = nbuckets;
- ptr->buckets =
- (struct hashentry_s**)safecalloc(nbuckets,
- sizeof(struct hashentry_s *));
+ ptr->buckets = safecalloc(nbuckets, sizeof(struct hashentry_s *));
if (!ptr->buckets) {
safefree(ptr);
return NULL;
@@ -225,7 +223,7 @@ hashmap_insert(hashmap_t map, const char *key,
data_copy = NULL;
}
- ptr = (struct hashentry_s*)safemalloc(sizeof(struct hashentry_s));
+ ptr = safemalloc(sizeof(struct hashentry_s));
if (!ptr) {
safefree(key_copy);
safefree(data_copy);
diff --git a/src/heap.c b/src/heap.c
index d8763b4..9125375 100644
--- a/src/heap.c
+++ b/src/heap.c
@@ -1,4 +1,4 @@
-/* $Id: heap.c,v 1.7 2003-07-31 23:42:51 rjkaes Exp $
+/* $Id: heap.c,v 1.8 2004-02-13 21:27:42 rjkaes Exp $
*
* Debugging versions of various heap related functions are combined
* here. The debugging versions include assertions and also print
@@ -82,7 +82,7 @@ debugging_strdup(const char* s, const char* file, unsigned long line)
assert(s != NULL);
len = strlen(s) + 1;
- ptr = (char*)malloc(len);
+ ptr = malloc(len);
if (!ptr)
return NULL;
memcpy(ptr, s, len);
@@ -113,11 +113,11 @@ malloc_shared_memory(size_t size)
strlcpy(buffer, shared_file, sizeof(buffer));
if ((fd = mkstemp(buffer)) == -1)
- return (void *)MAP_FAILED;
+ return MAP_FAILED;
unlink(buffer);
if (ftruncate(fd, size) == -1)
- return (void *)MAP_FAILED;
+ return MAP_FAILED;
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
return ptr;
diff --git a/src/http_message.c b/src/http_message.c
index 25ad2b6..6313da3 100644
--- a/src/http_message.c
+++ b/src/http_message.c
@@ -1,4 +1,4 @@
-/* $Id: http_message.c,v 1.3 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: http_message.c,v 1.4 2004-02-13 21:27:42 rjkaes Exp $
*
* See 'http_message.h' for a detailed description.
*
@@ -81,11 +81,11 @@ http_message_create(int response_code, const char* response_string)
http_message_t msg;
int ret;
- msg = (http_message_t)safecalloc(1, sizeof(struct http_message_s));
+ msg = safecalloc(1, sizeof(struct http_message_s));
if (msg == NULL)
return NULL;
- msg->headers.strings = (char**)safecalloc(NUMBER_OF_HEADERS, sizeof(char*));
+ msg->headers.strings = safecalloc(NUMBER_OF_HEADERS, sizeof(char*));
if (msg->headers.strings == NULL) {
safefree(msg);
return NULL;
@@ -182,8 +182,8 @@ http_message_add_headers(http_message_t msg, char** headers,
* available, reallocate the memory.
*/
if (msg->headers.used + num_headers > msg->headers.total) {
- new_headers = (char**)safecalloc(msg->headers.total * 2,
- sizeof(char*));
+ new_headers = safecalloc(msg->headers.total * 2,
+ sizeof(char*));
if (new_headers == NULL)
return -ENOMEM;
diff --git a/src/log.c b/src/log.c
index 2676594..387fbbf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,4 +1,4 @@
-/* $Id: log.c,v 1.27 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: log.c,v 1.28 2004-02-13 21:27:42 rjkaes Exp $
*
* Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it...
@@ -143,7 +143,7 @@ log_message(int level, char *fmt, ...)
vsnprintf(str, STRING_LENGTH, fmt, args);
- entry_buffer = (char*)safemalloc(strlen(str) + 6);
+ entry_buffer = safemalloc(strlen(str) + 6);
if (!entry_buffer)
return;
@@ -202,7 +202,7 @@ send_stored_logs(void)
int i;
for (i = 0; i != vector_length(log_message_storage); ++i) {
- string = (char*)vector_getentry(log_message_storage, i, NULL);
+ string = vector_getentry(log_message_storage, i, NULL);
ptr = strchr(string, ' ') + 1;
level = atoi(string);
diff --git a/src/network.c b/src/network.c
index a66857d..052c5cd 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1,4 +1,4 @@
-/* $Id: network.c,v 1.2 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: network.c,v 1.3 2004-02-13 21:27:42 rjkaes Exp $
*
* The functions found here are used for communicating across a
* network. They include both safe reading and writing (which are
@@ -90,7 +90,7 @@ write_message(int fd, const char *fmt, ...)
char *buf, *tmpbuf;
va_list ap;
- if ((buf = (char*)safemalloc(size)) == NULL)
+ if ((buf = safemalloc(size)) == NULL)
return -1;
while (1) {
@@ -110,7 +110,7 @@ write_message(int fd, const char *fmt, ...)
/* twice the old size (glibc2.0) */
size *= 2;
- if ((tmpbuf = (char*)saferealloc(buf, size)) == NULL) {
+ if ((tmpbuf = saferealloc(buf, size)) == NULL) {
safefree(buf);
return -1;
} else
@@ -154,8 +154,7 @@ readline(int fd, char **whole_buffer)
};
struct read_lines_s *first_line, *line_ptr;
- first_line =
- (struct read_lines_s*)safecalloc(sizeof(struct read_lines_s), 1);
+ first_line = safecalloc(sizeof(struct read_lines_s), 1);
if (!first_line)
return -ENOMEM;
@@ -167,7 +166,7 @@ readline(int fd, char **whole_buffer)
if (ret <= 0)
goto CLEANUP;
- ptr = (char*)memchr(buffer, '\n', ret);
+ ptr = memchr(buffer, '\n', ret);
if (ptr)
diff = ptr - buffer + 1;
else
@@ -184,7 +183,7 @@ readline(int fd, char **whole_buffer)
goto CLEANUP;
}
- line_ptr->data = (char*)safemalloc(diff);
+ line_ptr->data = safemalloc(diff);
if (!line_ptr->data) {
ret = -ENOMEM;
goto CLEANUP;
@@ -198,8 +197,7 @@ readline(int fd, char **whole_buffer)
break;
}
- line_ptr->next =
- (struct read_lines_s*)safecalloc(sizeof(struct read_lines_s), 1);
+ line_ptr->next = safecalloc(sizeof(struct read_lines_s), 1);
if (!line_ptr->next) {
ret = -ENOMEM;
goto CLEANUP;
@@ -207,7 +205,7 @@ readline(int fd, char **whole_buffer)
line_ptr = line_ptr->next;
}
- *whole_buffer = (char*)safemalloc(whole_buffer_len + 1);
+ *whole_buffer = safemalloc(whole_buffer_len + 1);
if (!*whole_buffer) {
ret = -ENOMEM;
goto CLEANUP;
diff --git a/src/reqs.c b/src/reqs.c
index 3cab70c..e03d6c4 100644
--- a/src/reqs.c
+++ b/src/reqs.c
@@ -1,4 +1,4 @@
-/* $Id: reqs.c,v 1.110 2004-02-04 19:57:40 rjkaes Exp $
+/* $Id: reqs.c,v 1.111 2004-02-13 21:27:42 rjkaes Exp $
*
* This is where all the work in tinyproxy is actually done. Incoming
* connections have a new child created for them. The child then
@@ -127,7 +127,7 @@ check_allowed_connect_ports(int port)
return 1;
for (i = 0; i != vector_length(ports_allowed_by_connect); ++i) {
- data = (int*)vector_getentry(ports_allowed_by_connect, i, NULL);
+ data = vector_getentry(ports_allowed_by_connect, i, NULL);
if (!data)
return -1;
@@ -288,7 +288,7 @@ extract_http_url(const char *url, struct request_s *request)
static int
extract_ssl_url(const char *url, struct request_s *request)
{
- request->host = (char*)safemalloc(strlen(url) + 1);
+ request->host = safemalloc(strlen(url) + 1);
if (!request->host)
return -1;
@@ -339,8 +339,7 @@ void
upstream_add(const char *host, int port, const char *domain)
{
char *ptr;
- struct upstream *up =
- (struct upstream*)safemalloc(sizeof (struct upstream));
+ struct upstream *up = safemalloc(sizeof (struct upstream));
if (!up) {
log_message(LOG_ERR, "Unable to allocate memory in upstream_add()");
@@ -613,15 +612,15 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders)
size_t request_len;
/* NULL out all the fields so frees don't cause segfaults. */
- request = (struct request_s*)safecalloc(1, sizeof(struct request_s));
+ request = safecalloc(1, sizeof(struct request_s));
if (!request)
return NULL;
request_len = strlen(connptr->request_line) + 1;
- request->method = (char*)safemalloc(request_len);
- url = (char*)safemalloc(request_len);
- request->protocol = (char*)safemalloc(request_len);
+ request->method = safemalloc(request_len);
+ url = safemalloc(request_len);
+ request->protocol = safemalloc(request_len);
if (!request->method || !url || !request->protocol) {
safefree(url);
@@ -926,7 +925,7 @@ pull_client_data(struct conn_s *connptr, long int length)
char *buffer;
ssize_t len;
- buffer = (char*)safemalloc(min(MAXBUFFSIZE, length));
+ buffer = safemalloc(min(MAXBUFFSIZE, length));
if (!buffer)
return -1;
@@ -1633,7 +1632,7 @@ connect_to_upstream(struct conn_s *connptr, struct request_s *request)
if (connptr->connect_method) {
len = strlen(request->host) + 7;
- combined_string = (char*)safemalloc(len);
+ combined_string = safemalloc(len);
if (!combined_string) {
return -1;
}
@@ -1642,7 +1641,7 @@ connect_to_upstream(struct conn_s *connptr, struct request_s *request)
request->port);
} else {
len = strlen(request->host) + strlen(request->path) + 14;
- combined_string = (char*)safemalloc(len);
+ combined_string = safemalloc(len);
if (!combined_string) {
return -1;
}
diff --git a/src/stats.c b/src/stats.c
index 88d9d0d..ab7efd2 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -1,4 +1,4 @@
-/* $Id: stats.c,v 1.14 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: stats.c,v 1.15 2004-02-13 21:27:42 rjkaes Exp $
*
* This module handles the statistics for tinyproxy. There are only two
* public API functions. The reason for the functions, rather than just a
@@ -45,7 +45,7 @@ static struct stat_s *stats;
void
init_stats(void)
{
- stats = (struct stat_s*)malloc_shared_memory(sizeof(struct stat_s));
+ stats = malloc_shared_memory(sizeof(struct stat_s));
if (stats == MAP_FAILED)
return;
@@ -81,7 +81,7 @@ showstats(struct conn_s *connptr)
snprintf(refused, sizeof(refused), "%lu", stats->num_refused);
if (!config.statpage || (!(statfile = fopen(config.statpage, "r")))) {
- message_buffer = (char*)safemalloc(MAXBUFFSIZE);
+ message_buffer = safemalloc(MAXBUFFSIZE);
if (!message_buffer)
return -1;
diff --git a/src/vector.c b/src/vector.c
index fc3d4e9..3c74d7e 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -1,4 +1,4 @@
-/* $Id: vector.c,v 1.10 2003-07-31 23:38:28 rjkaes Exp $
+/* $Id: vector.c,v 1.11 2004-02-13 21:27:41 rjkaes Exp $
*
* A vector implementation. The vector can be of an arbitrary length, and
* the data for each entry is an lump of data (the size is stored in the
@@ -58,7 +58,7 @@ vector_create(void)
{
vector_t vector;
- vector = (vector_t)safemalloc(sizeof(struct vector_s));
+ vector = safemalloc(sizeof(struct vector_s));
if (!vector)
return NULL;
@@ -118,7 +118,7 @@ vector_insert(vector_t vector, void *data, ssize_t len, int pos)
(pos != INSERT_PREPEND && pos != INSERT_APPEND))
return -EINVAL;
- entry = (struct vectorentry_s*)safemalloc(sizeof(struct vectorentry_s));
+ entry = safemalloc(sizeof(struct vectorentry_s));
if (!entry)
return -ENOMEM;