enhance portability (replace void* by char*)
When using void pointers in calculations, the behaviour is undefined. Arithmetic operations on 'void *' is a GNU C extension, which defines the 'sizeof(void)' to be 1.
This commit is contained in:
parent
a97603031c
commit
d2460a8a90
15
main.c
15
main.c
@ -180,12 +180,19 @@ char *make_full_path (char *s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
void running_for_first_time (void) {
|
||||
if (sizeof (void) != 1) {
|
||||
logprintf ("sizeof (void) isn't equal 1\n");
|
||||
logprintf ("GNU C compiler extension isn't available?\n");
|
||||
void check_type_sizes (void) {
|
||||
if (sizeof (int) != 4u) {
|
||||
logprintf ("sizeof (int) isn't equal 4.\n");
|
||||
exit (1);
|
||||
}
|
||||
if (sizeof (char) != 1u) {
|
||||
logprintf ("sizeof (char) isn't equal 1.\n");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
void running_for_first_time (void) {
|
||||
check_type_sizes ();
|
||||
if (config_filename) {
|
||||
return; // Do not create custom config file
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ long long rsa_encrypted_chunks, rsa_decrypted_chunks;
|
||||
BN_CTX *BN_ctx;
|
||||
int verbosity;
|
||||
|
||||
int get_random_bytes (void *buf, int n) {
|
||||
int get_random_bytes (unsigned char *buf, int n) {
|
||||
int r = 0, h = open ("/dev/random", O_RDONLY | O_NONBLOCK);
|
||||
if (h >= 0) {
|
||||
r = read (h, buf, n);
|
||||
|
@ -427,7 +427,7 @@ static inline void fetch_ints (void *data, int count) {
|
||||
in_ptr += count;
|
||||
}
|
||||
|
||||
int get_random_bytes (void *buf, int n);
|
||||
int get_random_bytes (unsigned char *buf, int n);
|
||||
|
||||
int pad_rsa_encrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *E);
|
||||
int pad_rsa_decrypt (char *from, int from_len, char *to, int size, BIGNUM *N, BIGNUM *D);
|
||||
|
9
net.c
9
net.c
@ -115,7 +115,8 @@ void delete_connection_buffer (struct connection_buffer *b) {
|
||||
free (b);
|
||||
}
|
||||
|
||||
int write_out (struct connection *c, const void *data, int len) {
|
||||
int write_out (struct connection *c, const void *_data, int len) {
|
||||
const unsigned char *data = _data;
|
||||
if (!len) { return 0; }
|
||||
assert (len > 0);
|
||||
int x = 0;
|
||||
@ -146,7 +147,8 @@ int write_out (struct connection *c, const void *data, int len) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int read_in (struct connection *c, void *data, int len) {
|
||||
int read_in (struct connection *c, void *_data, int len) {
|
||||
unsigned char *data = _data;
|
||||
if (!len) { return 0; }
|
||||
assert (len > 0);
|
||||
if (len > c->in_bytes) {
|
||||
@ -177,7 +179,8 @@ int read_in (struct connection *c, void *data, int len) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int read_in_lookup (struct connection *c, void *data, int len) {
|
||||
int read_in_lookup (struct connection *c, void *_data, int len) {
|
||||
unsigned char *data = _data;
|
||||
if (!len || !c->in_bytes) { return 0; }
|
||||
assert (len > 0);
|
||||
if (len > c->in_bytes) {
|
||||
|
8
net.h
8
net.h
@ -93,10 +93,10 @@ struct dc_serialized {
|
||||
};
|
||||
|
||||
struct connection_buffer {
|
||||
void *start;
|
||||
void *end;
|
||||
void *rptr;
|
||||
void *wptr;
|
||||
unsigned char *start;
|
||||
unsigned char *end;
|
||||
unsigned char *rptr;
|
||||
unsigned char *wptr;
|
||||
struct connection_buffer *next;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user