Remove more implicit casts that lost precision; declared function parameters as void if no function arguments were taken in.

This commit is contained in:
syb0rg 2014-04-23 19:37:27 -05:00
parent 1c920b85f6
commit 695e570e7f
13 changed files with 252 additions and 49 deletions

View file

@ -70,31 +70,31 @@ static struct encoder base128_encoder =
}; };
struct encoder struct encoder
*get_base128_encoder() *get_base128_encoder(void)
{ {
return &base128_encoder; return &base128_encoder;
} }
static int static int
base128_handles_dots() base128_handles_dots(void)
{ {
return 0; return 0;
} }
static int static int
base128_blksize_raw() base128_blksize_raw(void)
{ {
return BLKSIZE_RAW; return BLKSIZE_RAW;
} }
static int static int
base128_blksize_enc() base128_blksize_enc(void)
{ {
return BLKSIZE_ENC; return BLKSIZE_ENC;
} }
inline static void inline static void
base128_reverse_init() base128_reverse_init(void)
{ {
int i; int i;
unsigned char c; unsigned char c;

View file

@ -25,10 +25,8 @@
#define BLKSIZE_RAW 5 #define BLKSIZE_RAW 5
#define BLKSIZE_ENC 8 #define BLKSIZE_ENC 8
static const char cb32[] = static const char cb32[] = "abcdefghijklmnopqrstuvwxyz012345";
"abcdefghijklmnopqrstuvwxyz012345"; static const char cb32_ucase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
static const char cb32_ucase[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
static unsigned char rev32[256]; static unsigned char rev32[256];
static int reverse_init = 0; static int reverse_init = 0;
@ -50,31 +48,31 @@ static struct encoder base32_encoder =
}; };
struct encoder struct encoder
*get_base32_encoder() *get_base32_encoder(void)
{ {
return &base32_encoder; return &base32_encoder;
} }
static int static int
base32_handles_dots() base32_handles_dots(void)
{ {
return 0; return 0;
} }
static int static int
base32_blksize_raw() base32_blksize_raw(void)
{ {
return BLKSIZE_RAW; return BLKSIZE_RAW;
} }
static int static int
base32_blksize_enc() base32_blksize_enc(void)
{ {
return BLKSIZE_ENC; return BLKSIZE_ENC;
} }
inline static void inline static void
base32_reverse_init() base32_reverse_init(void)
{ {
int i; int i;
unsigned char c; unsigned char c;
@ -213,7 +211,7 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
int iout = 0; /* to-be-filled output byte */ int iout = 0; /* to-be-filled output byte */
int iin = 0; /* next input char to use in decoding */ int iin = 0; /* next input char to use in decoding */
base32_reverse_init (); base32_reverse_init();
/* Note: Don't bother to optimize manually. GCC optimizes /* Note: Don't bother to optimize manually. GCC optimizes
better(!) when using simplistic array indexing. */ better(!) when using simplistic array indexing. */

View file

@ -27,8 +27,7 @@
/* Note: the "unofficial" char is last here, which means that the \377 pattern /* Note: the "unofficial" char is last here, which means that the \377 pattern
in DOWNCODECCHECK1 ('Y' request) will properly test it. */ in DOWNCODECCHECK1 ('Y' request) will properly test it. */
static const char cb64[] = static const char cb64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
static unsigned char rev64[256]; static unsigned char rev64[256];
static int reverse_init = 0; static int reverse_init = 0;
@ -50,31 +49,31 @@ static struct encoder base64_encoder =
}; };
struct encoder struct encoder
*get_base64_encoder() *get_base64_encoder(void)
{ {
return &base64_encoder; return &base64_encoder;
} }
static int static int
base64_handles_dots() base64_handles_dots(void)
{ {
return 0; return 0;
} }
static int static int
base64_blksize_raw() base64_blksize_raw(void)
{ {
return BLKSIZE_RAW; return BLKSIZE_RAW;
} }
static int static int
base64_blksize_enc() base64_blksize_enc(void)
{ {
return BLKSIZE_ENC; return BLKSIZE_ENC;
} }
inline static void inline static void
base64_reverse_init() base64_reverse_init(void)
{ {
int i; int i;
unsigned char c; unsigned char c;

206
src/base64u.c Normal file
View file

@ -0,0 +1,206 @@
/* No use in editing, produced by Makefile! */
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
* Mostly rewritten 2009 J.A.Bezemer@opensourcepartners.nl
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encoding.h"
#include "base64u.h"
#define BLKSIZE_RAW 3
#define BLKSIZE_ENC 4
/* Note: the "unofficial" char is last here, which means that the \377 pattern
in DOWNCODECCHECK1 ('Y' request) will properly test it. */
static const char cb64[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789_";
static unsigned char rev64[256];
static int reverse_init = 0;
static int base64u_encode(char *, size_t *, const void *, size_t);
static int base64u_decode(void *, size_t *, const char *, size_t);
static int base64u_handles_dots();
static int base64u_blksize_raw();
static int base64u_blksize_enc();
static struct encoder base64u_encoder =
{
"Base64u",
base64u_encode,
base64u_decode,
base64u_handles_dots,
base64u_handles_dots,
base64u_blksize_raw,
base64u_blksize_enc
};
struct encoder
*get_base64u_encoder(void)
{
return &base64u_encoder;
}
static int
base64u_handles_dots(void)
{
return 0;
}
static int
base64u_blksize_raw(void)
{
return BLKSIZE_RAW;
}
static int
base64u_blksize_enc(void)
{
return BLKSIZE_ENC;
}
inline static void
base64u_reverse_init(void)
{
int i;
unsigned char c;
if (!reverse_init) {
memset (rev64, 0, 256);
for (i = 0; i < 64; i++) {
c = cb64[i];
rev64[(int) c] = i;
}
reverse_init = 1;
}
}
static int
base64u_encode(char *buf, size_t *buflen, const void *data, size_t size)
/*
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
*
* NOTE: *buf space should be at least 1 byte _more_ than *buflen
* to hold the trailing '\0'.
*
* return value : #bytes filled in buf (excluding \0)
* sets *buflen to : #bytes encoded from data
*/
{
unsigned char *udata = (unsigned char *) data;
int iout = 0; /* to-be-filled output char */
int iin = 0; /* one more than last input byte that can be
successfully decoded */
/* Note: Don't bother to optimize manually. GCC optimizes
better(!) when using simplistic array indexing. */
while (1) {
if (iout >= *buflen || iin >= size)
break;
buf[iout] = cb64[((udata[iin] & 0xfc) >> 2)];
iout++;
if (iout >= *buflen || iin >= size) {
iout--; /* previous char is useless */
break;
}
buf[iout] = cb64[((udata[iin] & 0x03) << 4) |
((iin + 1 < size) ?
((udata[iin + 1] & 0xf0) >> 4) : 0)];
iin++; /* 0 complete, iin=1 */
iout++;
if (iout >= *buflen || iin >= size)
break;
buf[iout] = cb64[((udata[iin] & 0x0f) << 2 ) |
((iin + 1 < size) ?
((udata[iin + 1] & 0xc0) >> 6) : 0)];
iin++; /* 1 complete, iin=2 */
iout++;
if (iout >= *buflen || iin >= size)
break;
buf[iout] = cb64[(udata[iin] & 0x3f)];
iin++; /* 2 complete, iin=3 */
iout++;
}
buf[iout] = '\0';
/* store number of bytes from data that was used */
*buflen = iin;
return iout;
}
#define REV64(x) rev64[(int) (x)]
static int
base64u_decode(void *buf, size_t *buflen, const char *str, size_t slen)
/*
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
* Decoding stops early when *str contains \0.
* Illegal encoded chars are assumed to decode to zero.
*
* NOTE: *buf space should be at least 1 byte _more_ than *buflen
* to hold a trailing '\0' that is added (though *buf will usually
* contain full-binary data).
*
* return value : #bytes filled in buf (excluding \0)
*/
{
unsigned char *ubuf = (unsigned char *) buf;
int iout = 0; /* to-be-filled output byte */
int iin = 0; /* next input char to use in decoding */
base64u_reverse_init ();
/* Note: Don't bother to optimize manually. GCC optimizes
better(!) when using simplistic array indexing. */
while (1) {
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
((REV64(str[iin + 1]) & 0x30) >> 4);
iin++; /* 0 used up, iin=1 */
iout++;
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
((REV64(str[iin + 1]) & 0x3c) >> 2);
iin++; /* 1 used up, iin=2 */
iout++;
if (iout >= *buflen || iin + 1 >= slen ||
str[iin] == '\0' || str[iin + 1] == '\0')
break;
ubuf[iout] = ((REV64(str[iin]) & 0x03) << 6) |
(REV64(str[iin + 1]) & 0x3f);
iin += 2; /* 2,3 used up, iin=4 */
iout++;
}
ubuf[iout] = '\0';
return iout;
}

View file

@ -110,7 +110,7 @@ static long send_query_recvcnt = 0;
static int hostname_maxlen = 0xFF; static int hostname_maxlen = 0xFF;
void void
client_init() client_init(void)
{ {
running = 1; running = 1;
b32 = get_base32_encoder(); b32 = get_base32_encoder();
@ -136,13 +136,13 @@ client_init()
} }
void void
client_stop() client_stop(void)
{ {
running = 0; running = 0;
} }
enum connection enum connection
client_get_conn() client_get_conn(void)
{ {
return conn; return conn;
} }
@ -232,7 +232,7 @@ client_set_hostname_maxlen(int i)
} }
const char * const char *
client_get_raw_addr() client_get_raw_addr(void)
{ {
return inet_ntoa(raw_serv.sin_addr); return inet_ntoa(raw_serv.sin_addr);
} }
@ -338,7 +338,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
} }
static inline int static inline int
is_sending() is_sending(void)
{ {
return (outpkt.len != 0); return (outpkt.len != 0);
} }

View file

@ -268,7 +268,7 @@ do_pidfile(char *pidfile)
} }
void void
do_detach() do_detach(void)
{ {
#ifndef WINDOWS32 #ifndef WINDOWS32
fprintf(stderr, "Detaching from terminal...\n"); fprintf(stderr, "Detaching from terminal...\n");

View file

@ -51,7 +51,7 @@ build_hostname(char *buf, size_t buflen,
strncpy(b, topdomain, strlen(topdomain)+1); strncpy(b, topdomain, strlen(topdomain)+1);
return space; return (int) space;
} }
int int
@ -70,7 +70,7 @@ inline_dotify(char *buf, size_t buflen)
unsigned total; unsigned total;
char *reader, *writer; char *reader, *writer;
total = strlen(buf); total = (int) strlen(buf);
dots = total / 57; dots = total / 57;
writer = buf; writer = buf;
@ -81,7 +81,7 @@ inline_dotify(char *buf, size_t buflen)
if (strlen(buf) + dots > buflen) { if (strlen(buf) + dots > buflen) {
writer = buf; writer = buf;
writer += buflen; writer += buflen;
total = buflen; total = (int) buflen;
} }
reader = writer - dots; reader = writer - dots;
@ -125,5 +125,5 @@ inline_undotify(char *buf, size_t len)
} }
/* return new length of string */ /* return new length of string */
return len - dots; return (int)(len - dots);
} }

View file

@ -20,7 +20,7 @@
static struct fw_query fwq[FW_QUERY_CACHE_SIZE]; static struct fw_query fwq[FW_QUERY_CACHE_SIZE];
static int fwq_ix; static int fwq_ix;
void fw_query_init() void fw_query_init(void)
{ {
memset(fwq, 0, sizeof(struct fw_query) * FW_QUERY_CACHE_SIZE); memset(fwq, 0, sizeof(struct fw_query) * FW_QUERY_CACHE_SIZE);
fwq_ix = 0; fwq_ix = 0;

View file

@ -58,7 +58,7 @@ sighandler(int sig)
} }
static void static void
usage() { usage(void) {
extern char *__progname; extern char *__progname;
fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-r] [-u user] [-t chrootdir] [-d device] " fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-r] [-u user] [-t chrootdir] [-d device] "
@ -68,7 +68,7 @@ usage() {
} }
static void static void
help() { help(void) {
extern char *__progname; extern char *__progname;
fprintf(stderr, "iodine IP over DNS tunneling client\n"); fprintf(stderr, "iodine IP over DNS tunneling client\n");
@ -101,7 +101,7 @@ help() {
} }
static void static void
version() { version(void) {
fprintf(stderr, "iodine IP over DNS tunneling client\n"); fprintf(stderr, "iodine IP over DNS tunneling client\n");
fprintf(stderr, "Git version: %s\n", GITREVISION); fprintf(stderr, "Git version: %s\n", GITREVISION);

View file

@ -2173,7 +2173,7 @@ write_dns(int fd, struct query *q, char *data, int datalen, char downenc)
} }
static void static void
usage() { usage(void) {
extern char *__progname; extern char *__progname;
fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] " fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
@ -2185,7 +2185,7 @@ usage() {
} }
static void static void
help() { help(void) {
extern char *__progname; extern char *__progname;
fprintf(stderr, "iodine IP over DNS tunneling server\n"); fprintf(stderr, "iodine IP over DNS tunneling server\n");
@ -2221,7 +2221,7 @@ help() {
} }
static void static void
version() { version(void) {
fprintf(stderr, "iodine IP over DNS tunneling server\n"); fprintf(stderr, "iodine IP over DNS tunneling server\n");
fprintf(stderr, "Git version: %s\n", GITREVISION); fprintf(stderr, "Git version: %s\n", GITREVISION);
exit(0); exit(0);

View file

@ -119,7 +119,7 @@ readdata(char *packet, char **src, char *dst, size_t len)
(*src) += len; (*src) += len;
return len; return (int) len;
} }
int int
@ -160,7 +160,7 @@ putname(char **buf, size_t buflen, const char *host)
char *p; char *p;
h = strdup(host); h = strdup(host);
left = buflen; left = (int) buflen;
p = *buf; p = *buf;
word = strtok(h, "."); word = strtok(h, ".");
@ -183,7 +183,7 @@ putname(char **buf, size_t buflen, const char *host)
free(h); free(h);
*buf = p; *buf = p;
return buflen - left; return (int) (buflen - left);
} }
int int
@ -232,7 +232,7 @@ putdata(char **dst, char *data, size_t len)
memcpy(*dst, data, len); memcpy(*dst, data, len);
(*dst) += len; (*dst) += len;
return len; return (int) len;
} }
int int
@ -246,7 +246,7 @@ puttxtbin(char **buf, size_t bufremain, char *from, size_t fromremain)
while (fromremain > 0) while (fromremain > 0)
{ {
tocopy = fromremain; tocopy = (int) fromremain;
if (tocopy > 252) if (tocopy > 252)
tocopy = 252; /* allow off-by-1s in caches etc */ tocopy = 252; /* allow off-by-1s in caches etc */
if (tocopy + 1 > bufremain) if (tocopy + 1 > bufremain)

View file

@ -82,7 +82,7 @@ init_users(in_addr_t my_ip, int netbits)
} }
const char* const char*
users_get_first_ip() users_get_first_ip(void)
{ {
struct in_addr ip; struct in_addr ip;
ip.s_addr = users[0].tun_ip; ip.s_addr = users[0].tun_ip;
@ -90,7 +90,7 @@ users_get_first_ip()
} }
int int
users_waiting_on_reply() users_waiting_on_reply(void)
{ {
int ret; int ret;
int i; int i;
@ -126,7 +126,7 @@ find_user_by_ip(uint32_t ip)
} }
int int
all_users_waiting_to_send() all_users_waiting_to_send(void)
/* If this returns true, then reading from tun device is blocked. /* If this returns true, then reading from tun device is blocked.
So only return true when all clients have at least one packet in So only return true when all clients have at least one packet in
the outpacket-queue, so that sending back-to-back is possible the outpacket-queue, so that sending back-to-back is possible
@ -159,7 +159,7 @@ all_users_waiting_to_send()
} }
int int
find_available_user() find_available_user(void)
{ {
int ret = -1; int ret = -1;
int i; int i;

View file

@ -18,7 +18,7 @@
#include "common.h" #include "common.h"
char * char *
get_resolvconf_addr() get_resolvconf_addr(void)
{ {
static char addr[16]; static char addr[16];
char *rv; char *rv;