Skip to content

Commit

Permalink
Re-enabling errors on warning, disabling unused parameter warning, an…
Browse files Browse the repository at this point in the history
…d fixing all subsequent errors.
  • Loading branch information
nicolasnoble committed Jan 30, 2015
1 parent c630682 commit 213ed91
Show file tree
Hide file tree
Showing 55 changed files with 97 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ LDFLAGS += $(LDFLAGS_$(CONFIG))

CFLAGS += -std=c89 -pedantic
CXXFLAGS += -std=c++11
CPPFLAGS += -g -fPIC -Wall -Wextra -Wno-long-long
CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
LDFLAGS += -g -fPIC

INCLUDES = . include gens
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/byte_buffer_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct grpc_byte_buffer_reader {
/* Different current objects correspond to different types of byte buffers */
union {
/* Index into a slice buffer's array of slices */
int index;
unsigned index;
} current;
};

Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ typedef uintmax_t gpr_uintmax;
typedef uintptr_t gpr_uintptr;

/* INT64_MAX is unavailable on some platforms. */
#define GPR_INT64_MAX (~(gpr_uint64)0 >> 1)
#define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1)

/* maximum alignment needed for any type on this platform, rounded up to a
power of two */
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/slice_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice);
void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n);
/* add a very small (less than 8 bytes) amount of data to the end of a slice
buffer: returns a pointer into which to add the data */
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int len);
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len);
/* clear a slice buffer, unref all elements */
void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb);

Expand Down
2 changes: 1 addition & 1 deletion src/core/channel/channel_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void grpc_channel_args_destroy(grpc_channel_args *a) {
}

int grpc_channel_args_is_census_enabled(const grpc_channel_args *a) {
int i;
unsigned i;
if (a == NULL) return 0;
for (i = 0; i < a->num_args; i++) {
if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_CENSUS)) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/channel/channel_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ void grpc_channel_stack_init(const grpc_channel_filter **filters,
call_size += ROUND_UP_TO_ALIGNMENT_SIZE(filters[i]->sizeof_call_data);
}

GPR_ASSERT(user_data - (char *)stack ==
GPR_ASSERT(user_data > (char *)stack);
GPR_ASSERT((gpr_uintptr)(user_data - (char *)stack) ==
grpc_channel_stack_size(filters, filter_count));

stack->call_stack_size = call_size;
Expand Down
2 changes: 1 addition & 1 deletion src/core/channel/http_client_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void destroy_call_elem(grpc_call_element *elem) {
}

static const char *scheme_from_args(const grpc_channel_args *args) {
int i;
unsigned i;
if (args != NULL) {
for (i = 0; i < args->num_args; ++i) {
if (args->args[i].type == GRPC_ARG_STRING &&
Expand Down
2 changes: 1 addition & 1 deletion src/core/iomgr/tcp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
The file descriptor remains owned by the server, and will be cleaned
up when grpc_tcp_server_destroy is called. */
int grpc_tcp_server_get_fd(grpc_tcp_server *s, int index);
int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index);

void grpc_tcp_server_destroy(grpc_tcp_server *server);

Expand Down
6 changes: 3 additions & 3 deletions src/core/iomgr/tcp_server_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
int addr_len) {
int allocated_port1 = -1;
int allocated_port2 = -1;
int i;
unsigned i;
int fd;
grpc_dualstack_mode dsmode;
struct sockaddr_in6 addr6_v4mapped;
Expand Down Expand Up @@ -345,8 +345,8 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
return allocated_port1 >= 0 ? allocated_port1 : allocated_port2;
}

int grpc_tcp_server_get_fd(grpc_tcp_server *s, int index) {
return (0 <= index && index < s->nports) ? s->ports[index].fd : -1;
int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index) {
return (index < s->nports) ? s->ports[index].fd : -1;
}

void grpc_tcp_server_start(grpc_tcp_server *s, grpc_pollset *pollset,
Expand Down
2 changes: 1 addition & 1 deletion src/core/json/json_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void json_writer_output_indent(
" "
" ";

int spaces = writer->depth * writer->indent;
unsigned spaces = writer->depth * writer->indent;

if (writer->indent == 0) return;

Expand Down
3 changes: 2 additions & 1 deletion src/core/security/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ char *grpc_base64_encode(const void *vdata, size_t data_size, int url_safe,
*current++ = GRPC_BASE64_PAD_CHAR;
}

GPR_ASSERT((current - result) < result_projected_size);
GPR_ASSERT(current >= result);
GPR_ASSERT((gpr_uintptr)(current - result) < result_projected_size);
result[current - result] = '\0';
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions src/core/security/credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ static void ssl_server_destroy(grpc_server_credentials *creds) {
gpr_free(creds);
}

static int ssl_has_request_metadata(const grpc_credentials *creds) { return 0; }
static int ssl_has_request_metadata(const grpc_credentials *creds) {
return 0;
}

static int ssl_has_request_metadata_only(const grpc_credentials *creds) {
return 0;
Expand Down Expand Up @@ -903,7 +905,9 @@ static void iam_destroy(grpc_credentials *creds) {
gpr_free(c);
}

static int iam_has_request_metadata(const grpc_credentials *creds) { return 1; }
static int iam_has_request_metadata(const grpc_credentials *creds) {
return 1;
}

static int iam_has_request_metadata_only(const grpc_credentials *creds) {
return 1;
Expand Down
6 changes: 4 additions & 2 deletions src/core/security/json_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
goto end;
}
bio = BIO_new(BIO_s_mem());
if (BIO_puts(bio, prop_value) != strlen(prop_value)) {
success = BIO_puts(bio, prop_value);
if ((success < 0) || ((size_t)success != strlen(prop_value))) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end;
}
Expand Down Expand Up @@ -240,7 +241,8 @@ static char *dot_concat_and_free_strings(char *str1, char *str2) {
*(current++) = '.';
memcpy(current, str2, str2_len);
current += str2_len;
GPR_ASSERT((current - result) == result_len);
GPR_ASSERT(current >= result);
GPR_ASSERT((gpr_uintptr)(current - result) == result_len);
*current = '\0';
gpr_free(str1);
gpr_free(str2);
Expand Down
4 changes: 2 additions & 2 deletions src/core/security/secure_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void call_read_cb(secure_endpoint *ep, gpr_slice *slices, size_t nslices,

static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
int i = 0;
unsigned i;
gpr_uint8 keep_looping = 0;
int input_buffer_count = 0;
tsi_result result = TSI_OK;
Expand Down Expand Up @@ -221,7 +221,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
size_t nslices,
grpc_endpoint_write_cb cb,
void *user_data) {
int i = 0;
unsigned i;
int output_buffer_count = 0;
tsi_result result = TSI_OK;
secure_endpoint *ep = (secure_endpoint *)secure_ep;
Expand Down
3 changes: 2 additions & 1 deletion src/core/security/server_secure_chttp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL;
size_t i;
int count = 0;
unsigned count = 0;
int port_num = -1;
int port_temp;

Expand Down Expand Up @@ -127,6 +127,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
if (count != resolved->naddrs) {
gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved",
count, resolved->naddrs);
/* if it's an error, don't we want to goto error; here ? */
}
grpc_resolved_addresses_destroy(resolved);

Expand Down
4 changes: 2 additions & 2 deletions src/core/statistics/census_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ typedef struct census_log_core_local_block {
struct census_log {
int discard_old_records;
/* Number of cores (aka hardware-contexts) */
int num_cores;
unsigned num_cores;
/* number of CENSUS_LOG_2_MAX_RECORD_SIZE blocks in log */
gpr_int32 num_blocks;
cl_block* blocks; /* Block metadata. */
Expand All @@ -183,7 +183,7 @@ struct census_log {
/* Keeps the state of the reader iterator. A value of 0 indicates that
iterator has reached the end. census_log_init_reader() resets the
value to num_core to restart iteration. */
gpr_int32 read_iterator_state;
gpr_uint32 read_iterator_state;
/* Points to the block being read. If non-NULL, the block is locked for
reading (block_being_read_->reader_lock is held). */
cl_block* block_being_read;
Expand Down
2 changes: 1 addition & 1 deletion src/core/statistics/census_rpc_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void get_stats(census_ht* store, census_aggregated_rpc_stats* data) {
gpr_mu_lock(&g_mu);
if (store != NULL) {
size_t n;
int i, j;
unsigned i, j;
gpr_timespec now = gpr_now();
census_ht_kv* kv = census_ht_get_all_elements(store, &n);
if (kv != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/statistics/hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static void ht_delete_entry_chain(const census_ht_option* options,
}

void census_ht_destroy(census_ht* ht) {
int i;
unsigned i;
for (i = 0; i < ht->num_buckets; ++i) {
ht_delete_entry_chain(&ht->options, ht->buckets[i].next);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/statistics/window_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ window_stats* census_window_stats_create(int nintervals,
is->width = size_ns / granularity;
/* Check for possible overflow issues, and maximize interval size if the
user requested something large enough. */
if (GPR_INT64_MAX - is->width > size_ns) {
if ((GPR_INT64_MAX - is->width) > size_ns) {
is->top = size_ns + is->width;
} else {
is->top = GPR_INT64_MAX;
Expand Down
4 changes: 2 additions & 2 deletions src/core/support/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

/* Return the number of CPU cores on the current system. Will return 0 if
if information is not available. */
int gpr_cpu_num_cores(void);
unsigned gpr_cpu_num_cores(void);

/* Return the CPU on which the current thread is executing; N.B. This should
be considered advisory only - it is possible that the thread is switched
to a different CPU at any time. Returns a value in range
[0, gpr_cpu_num_cores() - 1] */
int gpr_cpu_current_cpu(void);
unsigned gpr_cpu_current_cpu(void);

#endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */
5 changes: 3 additions & 2 deletions src/core/support/cpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@

#include <grpc/support/log.h>

int gpr_cpu_num_cores(void) {
unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0;
/* FIXME: !threadsafe */
if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus < 1) {
Expand All @@ -87,7 +88,7 @@ int gpr_cpu_num_cores(void) {
return ncpus;
}

int gpr_cpu_current_cpu(void) {
unsigned gpr_cpu_current_cpu(void) {
int cpu = sched_getcpu();
if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
Expand Down
4 changes: 2 additions & 2 deletions src/core/support/cpu_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

static __thread char magic_thread_local;

int gpr_cpu_num_cores(void) {
unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0;
if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
Expand All @@ -63,7 +63,7 @@ static size_t shard_ptr(const void *info) {
return ((x >> 4) ^ (x >> 9) ^ (x >> 14)) % gpr_cpu_num_cores();
}

int gpr_cpu_current_cpu(void) {
unsigned gpr_cpu_current_cpu(void) {
/* NOTE: there's no way I know to return the actual cpu index portably...
most code that's using this is using it to shard across work queues though,
so here we use thread identity instead to achieve a similar though not
Expand Down
1 change: 0 additions & 1 deletion src/core/support/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ static size_t bucket_for_unchecked(gpr_histogram *h, double x) {
/* bounds checked version of the above */
static size_t bucket_for(gpr_histogram *h, double x) {
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible));
GPR_ASSERT(bucket >= 0);
GPR_ASSERT(bucket < h->num_buckets);
return bucket;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/support/slice_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) {
gpr_free(sb->slices);
}

gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int n) {
gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) {
gpr_slice *back;
gpr_uint8 *out;

Expand All @@ -64,7 +64,7 @@ gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int n) {
if (sb->count == 0) goto add_new;
back = &sb->slices[sb->count - 1];
if (back->refcount) goto add_new;
if (back->data.inlined.length + n > sizeof(back->data.inlined.bytes))
if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes))
goto add_new;
out = back->data.inlined.bytes + back->data.inlined.length;
back->data.inlined.length += n;
Expand Down
4 changes: 2 additions & 2 deletions src/core/support/string_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (!(0 <= ret && ret < ~(size_t)0)) {
if (!(0 <= ret)) {
*strp = NULL;
return -1;
}
Expand All @@ -79,7 +79,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf(*strp, strp_buflen, format, args);
va_end(args);
if (ret == strp_buflen - 1) {
if ((size_t)ret == strp_buflen - 1) {
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/support/thd_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>

struct thd_arg {
void (*body)(void *arg); /* body of a thread */
Expand Down
2 changes: 1 addition & 1 deletion src/core/surface/server_chttp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int grpc_server_add_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL;
size_t i;
int count = 0;
unsigned count = 0;
int port_num = -1;
int port_temp;

Expand Down
3 changes: 2 additions & 1 deletion src/core/tsi/fake_transport_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h"

/* --- Constants. ---*/
Expand Down Expand Up @@ -412,7 +413,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer(
tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) {
tsi_result result = TSI_OK;
tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self;
int expected_msg = impl->next_message_to_send - 1;
tsi_fake_handshake_message expected_msg = impl->next_message_to_send - 1;
tsi_fake_handshake_message received_msg;

if (!impl->needs_incoming_message || impl->result == TSI_OK) {
Expand Down
7 changes: 5 additions & 2 deletions src/core/tsi/ssl_transport_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h"

#include <openssl/bio.h>
Expand Down Expand Up @@ -565,7 +566,8 @@ static tsi_result build_alpn_protocol_name_list(
current += alpn_protocols_lengths[i];
}
/* Safety check. */
if ((current - *protocol_name_list) != *protocol_name_list_length) {
if ((current < *protocol_name_list) ||
((gpr_uintptr)(current - *protocol_name_list) != *protocol_name_list_length)) {
return TSI_INTERNAL_ERROR;
}
return TSI_OK;
Expand Down Expand Up @@ -1063,7 +1065,8 @@ static int server_handshaker_factory_alpn_callback(
while ((client_current - in) < inlen) {
unsigned char client_current_len = *(client_current++);
const unsigned char* server_current = factory->alpn_protocol_list;
while ((server_current - factory->alpn_protocol_list) <
while ((server_current >= factory->alpn_protocol_list) &&
(gpr_uintptr)(server_current - factory->alpn_protocol_list) <
factory->alpn_protocol_list_length) {
unsigned char server_current_len = *(server_current++);
if ((client_current_len == server_current_len) &&
Expand Down
Loading

0 comments on commit 213ed91

Please sign in to comment.