Merge pull request #295 from nicolasnoble/warnings

Enabling extra warnings during compilation, and fixing code to shun them.
pull/299/merge
Craig Tiller 10 years ago
commit 904b711cdd
  1. 2
      Makefile
  2. 2
      include/grpc/byte_buffer_reader.h
  3. 2
      include/grpc/support/port_platform.h
  4. 2
      include/grpc/support/slice_buffer.h
  5. 2
      src/core/channel/channel_args.c
  6. 3
      src/core/channel/channel_stack.c
  7. 2
      src/core/channel/http_client_filter.c
  8. 2
      src/core/iomgr/tcp_server.h
  9. 6
      src/core/iomgr/tcp_server_posix.c
  10. 2
      src/core/json/json_writer.c
  11. 3
      src/core/security/base64.c
  12. 8
      src/core/security/credentials.c
  13. 6
      src/core/security/json_token.c
  14. 4
      src/core/security/secure_endpoint.c
  15. 3
      src/core/security/server_secure_chttp2.c
  16. 4
      src/core/statistics/census_log.c
  17. 2
      src/core/statistics/census_rpc_stats.c
  18. 2
      src/core/statistics/hash_table.c
  19. 2
      src/core/statistics/window_stats.c
  20. 4
      src/core/support/cpu.h
  21. 5
      src/core/support/cpu_linux.c
  22. 4
      src/core/support/cpu_posix.c
  23. 1
      src/core/support/histogram.c
  24. 4
      src/core/support/slice_buffer.c
  25. 4
      src/core/support/string_posix.c
  26. 1
      src/core/support/thd_posix.c
  27. 2
      src/core/surface/server_chttp2.c
  28. 3
      src/core/tsi/fake_transport_security.c
  29. 7
      src/core/tsi/ssl_transport_security.c
  30. 2
      templates/Makefile.template
  31. 2
      test/core/channel/channel_stack_test.c
  32. 4
      test/core/channel/metadata_buffer_test.c
  33. 2
      test/core/compression/message_compress_test.c
  34. 2
      test/core/echo/client.c
  35. 2
      test/core/echo/server.c
  36. 2
      test/core/end2end/tests/cancel_after_accept.c
  37. 2
      test/core/end2end/tests/cancel_after_accept_and_writes_closed.c
  38. 2
      test/core/end2end/tests/cancel_after_invoke.c
  39. 2
      test/core/end2end/tests/cancel_in_a_vacuum.c
  40. 2
      test/core/fling/client.c
  41. 6
      test/core/iomgr/resolve_address_test.c
  42. 7
      test/core/iomgr/sockaddr_utils_test.c
  43. 10
      test/core/iomgr/tcp_posix_test.c
  44. 2
      test/core/json/json_rewrite.c
  45. 4
      test/core/json/json_rewrite_test.c
  46. 2
      test/core/json/json_test.c
  47. 7
      test/core/security/secure_endpoint_test.c
  48. 6
      test/core/statistics/census_log_tests.c
  49. 2
      test/core/statistics/hash_table_test.c
  50. 3
      test/core/support/host_port_test.c
  51. 6
      test/core/support/slice_test.c
  52. 2
      test/core/surface/completion_queue_test.c
  53. 2
      test/core/transport/chttp2/timeout_encoding_test.c
  54. 2
      test/core/transport/stream_op_test.c
  55. 2
      test/core/transport/transport_end2end_tests.c

@ -122,7 +122,7 @@ LDFLAGS += $(LDFLAGS_$(CONFIG))
CFLAGS += -std=c89 -pedantic CFLAGS += -std=c89 -pedantic
CXXFLAGS += -std=c++11 CXXFLAGS += -std=c++11
CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
LDFLAGS += -g -fPIC LDFLAGS += -g -fPIC
INCLUDES = . include gens INCLUDES = . include gens

@ -42,7 +42,7 @@ struct grpc_byte_buffer_reader {
/* Different current objects correspond to different types of byte buffers */ /* Different current objects correspond to different types of byte buffers */
union { union {
/* Index into a slice buffer's array of slices */ /* Index into a slice buffer's array of slices */
int index; unsigned index;
} current; } current;
}; };

@ -155,7 +155,7 @@ typedef uintmax_t gpr_uintmax;
typedef uintptr_t gpr_uintptr; typedef uintptr_t gpr_uintptr;
/* INT64_MAX is unavailable on some platforms. */ /* 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 /* maximum alignment needed for any type on this platform, rounded up to a
power of two */ power of two */

@ -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); 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 /* 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 */ 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 */ /* clear a slice buffer, unref all elements */
void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb); void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb);

@ -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 grpc_channel_args_is_census_enabled(const grpc_channel_args *a) {
int i; unsigned i;
if (a == NULL) return 0; if (a == NULL) return 0;
for (i = 0; i < a->num_args; i++) { for (i = 0; i < a->num_args; i++) {
if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_CENSUS)) { if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_CENSUS)) {

@ -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); 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)); grpc_channel_stack_size(filters, filter_count));
stack->call_stack_size = call_size; stack->call_stack_size = call_size;

@ -134,7 +134,7 @@ static void destroy_call_elem(grpc_call_element *elem) {
} }
static const char *scheme_from_args(const grpc_channel_args *args) { static const char *scheme_from_args(const grpc_channel_args *args) {
int i; unsigned i;
if (args != NULL) { if (args != NULL) {
for (i = 0; i < args->num_args; ++i) { for (i = 0; i < args->num_args; ++i) {
if (args->args[i].type == GRPC_ARG_STRING && if (args->args[i].type == GRPC_ARG_STRING &&

@ -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 The file descriptor remains owned by the server, and will be cleaned
up when grpc_tcp_server_destroy is called. */ 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); void grpc_tcp_server_destroy(grpc_tcp_server *server);

@ -272,7 +272,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
int addr_len) { int addr_len) {
int allocated_port1 = -1; int allocated_port1 = -1;
int allocated_port2 = -1; int allocated_port2 = -1;
int i; unsigned i;
int fd; int fd;
grpc_dualstack_mode dsmode; grpc_dualstack_mode dsmode;
struct sockaddr_in6 addr6_v4mapped; struct sockaddr_in6 addr6_v4mapped;
@ -345,8 +345,8 @@ done:
return allocated_port1 >= 0 ? allocated_port1 : allocated_port2; return allocated_port1 >= 0 ? allocated_port1 : allocated_port2;
} }
int grpc_tcp_server_get_fd(grpc_tcp_server *s, int index) { int grpc_tcp_server_get_fd(grpc_tcp_server *s, unsigned index) {
return (0 <= index && index < s->nports) ? s->ports[index].fd : -1; return (index < s->nports) ? s->ports[index].fd : -1;
} }
void grpc_tcp_server_start(grpc_tcp_server *s, grpc_pollset *pollset, void grpc_tcp_server_start(grpc_tcp_server *s, grpc_pollset *pollset,

@ -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; if (writer->indent == 0) return;

@ -113,7 +113,8 @@ char *grpc_base64_encode(const void *vdata, size_t data_size, int url_safe,
*current++ = GRPC_BASE64_PAD_CHAR; *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'; result[current - result] = '\0';
return result; return result;
} }

@ -173,7 +173,9 @@ static void ssl_server_destroy(grpc_server_credentials *creds) {
gpr_free(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) { static int ssl_has_request_metadata_only(const grpc_credentials *creds) {
return 0; return 0;
@ -903,7 +905,9 @@ static void iam_destroy(grpc_credentials *creds) {
gpr_free(c); 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) { static int iam_has_request_metadata_only(const grpc_credentials *creds) {
return 1; return 1;

@ -127,7 +127,8 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
goto end; goto end;
} }
bio = BIO_new(BIO_s_mem()); 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."); gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end; goto end;
} }
@ -240,7 +241,8 @@ static char *dot_concat_and_free_strings(char *str1, char *str2) {
*(current++) = '.'; *(current++) = '.';
memcpy(current, str2, str2_len); memcpy(current, str2, str2_len);
current += 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'; *current = '\0';
gpr_free(str1); gpr_free(str1);
gpr_free(str2); gpr_free(str2);

@ -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, static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) { grpc_endpoint_cb_status error) {
int i = 0; unsigned i;
gpr_uint8 keep_looping = 0; gpr_uint8 keep_looping = 0;
int input_buffer_count = 0; int input_buffer_count = 0;
tsi_result result = TSI_OK; tsi_result result = TSI_OK;
@ -221,7 +221,7 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
size_t nslices, size_t nslices,
grpc_endpoint_write_cb cb, grpc_endpoint_write_cb cb,
void *user_data) { void *user_data) {
int i = 0; unsigned i;
int output_buffer_count = 0; int output_buffer_count = 0;
tsi_result result = TSI_OK; tsi_result result = TSI_OK;
secure_endpoint *ep = (secure_endpoint *)secure_ep; secure_endpoint *ep = (secure_endpoint *)secure_ep;

@ -92,7 +92,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL; grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL; grpc_tcp_server *tcp = NULL;
size_t i; size_t i;
int count = 0; unsigned count = 0;
int port_num = -1; int port_num = -1;
int port_temp; int port_temp;
@ -127,6 +127,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr) {
if (count != resolved->naddrs) { if (count != resolved->naddrs) {
gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved", gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved",
count, resolved->naddrs); count, resolved->naddrs);
/* if it's an error, don't we want to goto error; here ? */
} }
grpc_resolved_addresses_destroy(resolved); grpc_resolved_addresses_destroy(resolved);

@ -173,7 +173,7 @@ typedef struct census_log_core_local_block {
struct census_log { struct census_log {
int discard_old_records; int discard_old_records;
/* Number of cores (aka hardware-contexts) */ /* Number of cores (aka hardware-contexts) */
int num_cores; unsigned num_cores;
/* number of CENSUS_LOG_2_MAX_RECORD_SIZE blocks in log */ /* number of CENSUS_LOG_2_MAX_RECORD_SIZE blocks in log */
gpr_int32 num_blocks; gpr_int32 num_blocks;
cl_block* blocks; /* Block metadata. */ cl_block* blocks; /* Block metadata. */
@ -183,7 +183,7 @@ struct census_log {
/* Keeps the state of the reader iterator. A value of 0 indicates that /* Keeps the state of the reader iterator. A value of 0 indicates that
iterator has reached the end. census_log_init_reader() resets the iterator has reached the end. census_log_init_reader() resets the
value to num_core to restart iteration. */ 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 /* Points to the block being read. If non-NULL, the block is locked for
reading (block_being_read_->reader_lock is held). */ reading (block_being_read_->reader_lock is held). */
cl_block* block_being_read; cl_block* block_being_read;

@ -184,7 +184,7 @@ static void get_stats(census_ht* store, census_aggregated_rpc_stats* data) {
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
if (store != NULL) { if (store != NULL) {
size_t n; size_t n;
int i, j; unsigned i, j;
gpr_timespec now = gpr_now(); gpr_timespec now = gpr_now();
census_ht_kv* kv = census_ht_get_all_elements(store, &n); census_ht_kv* kv = census_ht_get_all_elements(store, &n);
if (kv != NULL) { if (kv != NULL) {

@ -292,7 +292,7 @@ static void ht_delete_entry_chain(const census_ht_option* options,
} }
void census_ht_destroy(census_ht* ht) { void census_ht_destroy(census_ht* ht) {
int i; unsigned i;
for (i = 0; i < ht->num_buckets; ++i) { for (i = 0; i < ht->num_buckets; ++i) {
ht_delete_entry_chain(&ht->options, ht->buckets[i].next); ht_delete_entry_chain(&ht->options, ht->buckets[i].next);
} }

@ -150,7 +150,7 @@ window_stats* census_window_stats_create(int nintervals,
is->width = size_ns / granularity; is->width = size_ns / granularity;
/* Check for possible overflow issues, and maximize interval size if the /* Check for possible overflow issues, and maximize interval size if the
user requested something large enough. */ 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; is->top = size_ns + is->width;
} else { } else {
is->top = GPR_INT64_MAX; is->top = GPR_INT64_MAX;

@ -38,12 +38,12 @@
/* Return the number of CPU cores on the current system. Will return 0 if /* Return the number of CPU cores on the current system. Will return 0 if
if information is not available. */ 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 /* 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 be considered advisory only - it is possible that the thread is switched
to a different CPU at any time. Returns a value in range to a different CPU at any time. Returns a value in range
[0, gpr_cpu_num_cores() - 1] */ [0, gpr_cpu_num_cores() - 1] */
int gpr_cpu_current_cpu(void); unsigned gpr_cpu_current_cpu(void);
#endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */ #endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */

@ -75,8 +75,9 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
int gpr_cpu_num_cores(void) { unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0; static int ncpus = 0;
/* FIXME: !threadsafe */
if (ncpus == 0) { if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN); ncpus = sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus < 1) { if (ncpus < 1) {
@ -87,7 +88,7 @@ int gpr_cpu_num_cores(void) {
return ncpus; return ncpus;
} }
int gpr_cpu_current_cpu(void) { unsigned gpr_cpu_current_cpu(void) {
int cpu = sched_getcpu(); int cpu = sched_getcpu();
if (cpu < 0) { if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno)); gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));

@ -45,7 +45,7 @@
static __thread char magic_thread_local; static __thread char magic_thread_local;
int gpr_cpu_num_cores(void) { unsigned gpr_cpu_num_cores(void) {
static int ncpus = 0; static int ncpus = 0;
if (ncpus == 0) { if (ncpus == 0) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN); ncpus = sysconf(_SC_NPROCESSORS_ONLN);
@ -63,7 +63,7 @@ static size_t shard_ptr(const void *info) {
return ((x >> 4) ^ (x >> 9) ^ (x >> 14)) % gpr_cpu_num_cores(); 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... /* 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, 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 so here we use thread identity instead to achieve a similar though not

@ -77,7 +77,6 @@ static size_t bucket_for_unchecked(gpr_histogram *h, double x) {
/* bounds checked version of the above */ /* bounds checked version of the above */
static size_t bucket_for(gpr_histogram *h, double x) { static size_t bucket_for(gpr_histogram *h, double x) {
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible)); size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible));
GPR_ASSERT(bucket >= 0);
GPR_ASSERT(bucket < h->num_buckets); GPR_ASSERT(bucket < h->num_buckets);
return bucket; return bucket;
} }

@ -55,7 +55,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) {
gpr_free(sb->slices); 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_slice *back;
gpr_uint8 *out; gpr_uint8 *out;
@ -64,7 +64,7 @@ gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, int n) {
if (sb->count == 0) goto add_new; if (sb->count == 0) goto add_new;
back = &sb->slices[sb->count - 1]; back = &sb->slices[sb->count - 1];
if (back->refcount) goto add_new; 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; goto add_new;
out = back->data.inlined.bytes + back->data.inlined.length; out = back->data.inlined.bytes + back->data.inlined.length;
back->data.inlined.length += n; back->data.inlined.length += n;

@ -57,7 +57,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format); va_start(args, format);
ret = vsnprintf(buf, sizeof(buf), format, args); ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args); va_end(args);
if (!(0 <= ret && ret < ~(size_t)0)) { if (!(0 <= ret)) {
*strp = NULL; *strp = NULL;
return -1; return -1;
} }
@ -79,7 +79,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format); va_start(args, format);
ret = vsnprintf(*strp, strp_buflen, format, args); ret = vsnprintf(*strp, strp_buflen, format, args);
va_end(args); va_end(args);
if (ret == strp_buflen - 1) { if ((size_t)ret == strp_buflen - 1) {
return ret; return ret;
} }

@ -43,6 +43,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/thd.h> #include <grpc/support/thd.h>
#include <grpc/support/useful.h>
struct thd_arg { struct thd_arg {
void (*body)(void *arg); /* body of a thread */ void (*body)(void *arg); /* body of a thread */

@ -75,7 +75,7 @@ int grpc_server_add_http2_port(grpc_server *server, const char *addr) {
grpc_resolved_addresses *resolved = NULL; grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp = NULL; grpc_tcp_server *tcp = NULL;
size_t i; size_t i;
int count = 0; unsigned count = 0;
int port_num = -1; int port_num = -1;
int port_temp; int port_temp;

@ -38,6 +38,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h" #include "src/core/tsi/transport_security.h"
/* --- Constants. ---*/ /* --- Constants. ---*/
@ -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_handshaker* self, const unsigned char* bytes, size_t* bytes_size) {
tsi_result result = TSI_OK; tsi_result result = TSI_OK;
tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; 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; tsi_fake_handshake_message received_msg;
if (!impl->needs_incoming_message || impl->result == TSI_OK) { if (!impl->needs_incoming_message || impl->result == TSI_OK) {

@ -37,6 +37,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/sync.h> #include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h" #include "src/core/tsi/transport_security.h"
#include <openssl/bio.h> #include <openssl/bio.h>
@ -565,7 +566,8 @@ static tsi_result build_alpn_protocol_name_list(
current += alpn_protocols_lengths[i]; current += alpn_protocols_lengths[i];
} }
/* Safety check. */ /* 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_INTERNAL_ERROR;
} }
return TSI_OK; return TSI_OK;
@ -1063,7 +1065,8 @@ static int server_handshaker_factory_alpn_callback(
while ((client_current - in) < inlen) { while ((client_current - in) < inlen) {
unsigned char client_current_len = *(client_current++); unsigned char client_current_len = *(client_current++);
const unsigned char* server_current = factory->alpn_protocol_list; 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) { factory->alpn_protocol_list_length) {
unsigned char server_current_len = *(server_current++); unsigned char server_current_len = *(server_current++);
if ((client_current_len == server_current_len) && if ((client_current_len == server_current_len) &&

@ -139,7 +139,7 @@ LDFLAGS += $(LDFLAGS_$(CONFIG))
CFLAGS += -std=c89 -pedantic CFLAGS += -std=c89 -pedantic
CXXFLAGS += -std=c++11 CXXFLAGS += -std=c++11
CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
LDFLAGS += -g -fPIC LDFLAGS += -g -fPIC
INCLUDES = . include gens INCLUDES = . include gens

@ -80,7 +80,7 @@ static void test_create_channel_stack(void) {
const grpc_channel_filter const grpc_channel_filter
filter = {call_func, channel_func, sizeof(int), filter = {call_func, channel_func, sizeof(int),
call_init_func, call_destroy_func, sizeof(int), call_init_func, call_destroy_func, sizeof(int),
channel_init_func, channel_destroy_func, }; channel_init_func, channel_destroy_func, "some_test_filter" };
const grpc_channel_filter *filters = &filter; const grpc_channel_filter *filters = &filter;
grpc_channel_stack *channel_stack; grpc_channel_stack *channel_stack;
grpc_call_stack *call_stack; grpc_call_stack *call_stack;

@ -112,12 +112,12 @@ static void destroy_channel_elem(grpc_channel_element *elem) {}
static const grpc_channel_filter top_filter = { static const grpc_channel_filter top_filter = {
fail_call_op, fail_channel_op, sizeof(size_t), fail_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data), init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem}; init_channel_elem, destroy_channel_elem, "top_filter" };
static const grpc_channel_filter bottom_filter = { static const grpc_channel_filter bottom_filter = {
expect_call_op, fail_channel_op, sizeof(size_t), expect_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data), init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem}; init_channel_elem, destroy_channel_elem, "bottom_filter" };
static const grpc_channel_filter *filters[2] = {&top_filter, &bottom_filter}; static const grpc_channel_filter *filters[2] = {&top_filter, &bottom_filter};

@ -166,7 +166,7 @@ static void test_bad_data(void) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i, j, k, m; unsigned i, j, k, m;
grpc_slice_split_mode uncompressed_split_modes[] = { grpc_slice_split_mode uncompressed_split_modes[] = {
GRPC_SLICE_SPLIT_IDENTITY, GRPC_SLICE_SPLIT_ONE_BYTE}; GRPC_SLICE_SPLIT_IDENTITY, GRPC_SLICE_SPLIT_ONE_BYTE};
grpc_slice_split_mode compressed_split_modes[] = {GRPC_SLICE_SPLIT_MERGE_ALL, grpc_slice_split_mode compressed_split_modes[] = {GRPC_SLICE_SPLIT_MERGE_ALL,

@ -66,7 +66,7 @@ int main(int argc, char **argv) {
grpc_completion_queue *cq = NULL; grpc_completion_queue *cq = NULL;
int bytes_written = 0; int bytes_written = 0;
int bytes_read = 0; int bytes_read = 0;
int i = 0; unsigned i = 0;
int waiting_finishes; int waiting_finishes;
gpr_slice read_slice; gpr_slice read_slice;

@ -70,7 +70,7 @@ static void request_call(void) {
static void assert_read_ok(call_state *s, grpc_byte_buffer *b) { static void assert_read_ok(call_state *s, grpc_byte_buffer *b) {
grpc_byte_buffer_reader *bb_reader = NULL; grpc_byte_buffer_reader *bb_reader = NULL;
gpr_slice read_slice; gpr_slice read_slice;
int i; unsigned i;
bb_reader = grpc_byte_buffer_reader_create(b); bb_reader = grpc_byte_buffer_reader_create(b);
while (grpc_byte_buffer_reader_next(bb_reader, &read_slice)) { while (grpc_byte_buffer_reader_next(bb_reader, &read_slice)) {

@ -149,7 +149,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
} }
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_accept(config, cancellation_modes[i]); test_cancel_after_accept(config, cancellation_modes[i]);

@ -157,7 +157,7 @@ static void test_cancel_after_accept_and_writes_closed(
} }
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_accept_and_writes_closed(config, cancellation_modes[i]); test_cancel_after_accept_and_writes_closed(config, cancellation_modes[i]);

@ -132,7 +132,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
} }
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_after_invoke(config, cancellation_modes[i]); test_cancel_after_invoke(config, cancellation_modes[i]);

@ -122,7 +122,7 @@ static void test_cancel_in_a_vacuum(grpc_end2end_test_config config,
} }
void grpc_end2end_tests(grpc_end2end_test_config config) { void grpc_end2end_tests(grpc_end2end_test_config config) {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) { for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
test_cancel_in_a_vacuum(config, cancellation_modes[i]); test_cancel_in_a_vacuum(config, cancellation_modes[i]);

@ -103,7 +103,7 @@ static const scenario scenarios[] = {
int main(int argc, char **argv) { int main(int argc, char **argv) {
gpr_slice slice = gpr_slice_from_copied_string("x"); gpr_slice slice = gpr_slice_from_copied_string("x");
double start, stop; double start, stop;
int i; unsigned i;
char *fake_argv[1]; char *fake_argv[1];

@ -85,7 +85,7 @@ static void test_ipv6_with_port(void) {
static void test_ipv6_without_port(void) { static void test_ipv6_without_port(void) {
const char* const kCases[] = {"2001:db8::1", "2001:db8::1.2.3.4", const char* const kCases[] = {"2001:db8::1", "2001:db8::1.2.3.4",
"[2001:db8::1]", }; "[2001:db8::1]", };
int i; unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev; gpr_event ev;
gpr_event_init(&ev); gpr_event_init(&ev);
@ -96,7 +96,7 @@ static void test_ipv6_without_port(void) {
static void test_invalid_ip_addresses(void) { static void test_invalid_ip_addresses(void) {
const char* const kCases[] = {"293.283.1238.3:1", "[2001:db8::11111]:1", }; const char* const kCases[] = {"293.283.1238.3:1", "[2001:db8::11111]:1", };
int i; unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev; gpr_event ev;
gpr_event_init(&ev); gpr_event_init(&ev);
@ -108,7 +108,7 @@ static void test_invalid_ip_addresses(void) {
static void test_unparseable_hostports(void) { static void test_unparseable_hostports(void) {
const char* const kCases[] = {"[", "[::1", "[::1]bad", const char* const kCases[] = {"[", "[::1", "[::1]bad",
"[1.2.3.4]", "[localhost]", "[localhost]:1", }; "[1.2.3.4]", "[localhost]", "[localhost]:1", };
int i; unsigned i;
for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) { for (i = 0; i < sizeof(kCases) / sizeof(*kCases); i++) {
gpr_event ev; gpr_event ev;
gpr_event_init(&ev); gpr_event_init(&ev);

@ -182,7 +182,8 @@ static void expect_sockaddr_str(const char *expected, void *addr,
gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected); gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected);
result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize); result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize);
GPR_ASSERT(str != NULL); GPR_ASSERT(str != NULL);
GPR_ASSERT(result == strlen(str)); GPR_ASSERT(result >= 0);
GPR_ASSERT((size_t)result == strlen(str));
GPR_ASSERT(strcmp(expected, str) == 0); GPR_ASSERT(strcmp(expected, str) == 0);
gpr_free(str); gpr_free(str);
} }
@ -194,7 +195,7 @@ static void test_sockaddr_to_string(void) {
gpr_log(GPR_INFO, "%s", __FUNCTION__); gpr_log(GPR_INFO, "%s", __FUNCTION__);
errno = 0xDEADBEEF; errno = 0x7EADBEEF;
input4 = make_addr4(kIPv4, sizeof(kIPv4)); input4 = make_addr4(kIPv4, sizeof(kIPv4));
expect_sockaddr_str("192.0.2.1:12345", &input4, 0); expect_sockaddr_str("192.0.2.1:12345", &input4, 0);
@ -217,7 +218,7 @@ static void test_sockaddr_to_string(void) {
expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 0);
expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1);
GPR_ASSERT(errno == 0xDEADBEEF); GPR_ASSERT(errno == 0x7EADBEEF);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {

@ -94,7 +94,7 @@ static size_t fill_socket_partial(int fd, size_t bytes) {
ssize_t write_bytes; ssize_t write_bytes;
size_t total_bytes = 0; size_t total_bytes = 0;
unsigned char *buf = malloc(bytes); unsigned char *buf = malloc(bytes);
int i; unsigned i;
for (i = 0; i < bytes; ++i) { for (i = 0; i < bytes; ++i) {
buf[i] = i % 256; buf[i] = i % 256;
} }
@ -115,15 +115,14 @@ struct read_socket_state {
grpc_endpoint *ep; grpc_endpoint *ep;
gpr_mu mu; gpr_mu mu;
gpr_cv cv; gpr_cv cv;
size_t read_bytes; ssize_t read_bytes;
ssize_t target_read_bytes; ssize_t target_read_bytes;
}; };
static ssize_t count_and_unref_slices(gpr_slice *slices, size_t nslices, static ssize_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
int *current_data) { int *current_data) {
ssize_t num_bytes = 0; ssize_t num_bytes = 0;
int i; unsigned i, j;
int j;
unsigned char *buf; unsigned char *buf;
for (i = 0; i < nslices; ++i) { for (i = 0; i < nslices; ++i) {
buf = GPR_SLICE_START_PTR(slices[i]); buf = GPR_SLICE_START_PTR(slices[i]);
@ -254,8 +253,7 @@ static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size,
ssize_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); ssize_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices);
ssize_t num_bytes_left = num_bytes; ssize_t num_bytes_left = num_bytes;
int i; unsigned i, j;
int j;
unsigned char *buf; unsigned char *buf;
*num_blocks = nslices; *num_blocks = nslices;

@ -131,7 +131,7 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
} }
static gpr_uint32 json_reader_read_char(void* userdata) { static gpr_uint32 json_reader_read_char(void* userdata) {
gpr_uint32 r; int r;
json_reader_userdata* state = userdata; json_reader_userdata* state = userdata;
r = fgetc(state->in); r = fgetc(state->in);

@ -138,7 +138,7 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
} }
static gpr_uint32 json_reader_read_char(void* userdata) { static gpr_uint32 json_reader_read_char(void* userdata) {
gpr_uint32 r; int r;
json_reader_userdata* state = userdata; json_reader_userdata* state = userdata;
if (!state->did_eagain) { if (!state->did_eagain) {
@ -298,7 +298,7 @@ static test_file test_files[] = {
}; };
void test_rewrites() { void test_rewrites() {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) { for (i = 0; i < GPR_ARRAY_SIZE(test_files); i++) {
test_file* test = test_files + i; test_file* test = test_files + i;

@ -124,7 +124,7 @@ static testing_pair testing_pairs[] = {
}; };
static void test_pairs() { static void test_pairs() {
int i; unsigned i;
for (i = 0; i < GPR_ARRAY_SIZE(testing_pairs); i++) { for (i = 0; i < GPR_ARRAY_SIZE(testing_pairs); i++) {
testing_pair* pair = testing_pairs + i; testing_pair* pair = testing_pairs + i;

@ -59,7 +59,7 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
f.client_ep = f.client_ep =
grpc_secure_endpoint_create(fake_read_protector, tcp.client, NULL, 0); grpc_secure_endpoint_create(fake_read_protector, tcp.client, NULL, 0);
} else { } else {
int i; unsigned i;
tsi_result result; tsi_result result;
size_t still_pending_size; size_t still_pending_size;
size_t total_buffer_size = 8192; size_t total_buffer_size = 8192;
@ -81,9 +81,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
message_bytes += processed_message_size; message_bytes += processed_message_size;
message_size -= processed_message_size; message_size -= processed_message_size;
cur += protected_buffer_size_to_send; cur += protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= protected_buffer_size_to_send);
buffer_size -= protected_buffer_size_to_send; buffer_size -= protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= 0);
} }
gpr_slice_unref(plain); gpr_slice_unref(plain);
} }
@ -94,8 +93,8 @@ static grpc_endpoint_test_fixture secure_endpoint_create_fixture_tcp_socketpair(
&still_pending_size); &still_pending_size);
GPR_ASSERT(result == TSI_OK); GPR_ASSERT(result == TSI_OK);
cur += protected_buffer_size_to_send; cur += protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= protected_buffer_size_to_send);
buffer_size -= protected_buffer_size_to_send; buffer_size -= protected_buffer_size_to_send;
GPR_ASSERT(buffer_size >= 0);
} while (still_pending_size > 0); } while (still_pending_size > 0);
encrypted_leftover = gpr_slice_from_copied_buffer( encrypted_leftover = gpr_slice_from_copied_buffer(
(const char *)encrypted_buffer, total_buffer_size - buffer_size); (const char *)encrypted_buffer, total_buffer_size - buffer_size);

@ -415,8 +415,8 @@ void test_read_pending_record(void) {
/* Tries reading beyond pending write. */ /* Tries reading beyond pending write. */
void test_read_beyond_pending_record(void) { void test_read_beyond_pending_record(void) {
/* Start a write. */ /* Start a write. */
gpr_int32 incomplete_record_size = 10; gpr_uint32 incomplete_record_size = 10;
gpr_int32 complete_record_size = 20; gpr_uint32 complete_record_size = 20;
size_t bytes_available; size_t bytes_available;
void* complete_record; void* complete_record;
const void* record_read; const void* record_read;
@ -457,7 +457,7 @@ void test_detached_while_reading(void) {
size_t bytes_available; size_t bytes_available;
const void* record_read; const void* record_read;
void* record_written; void* record_written;
gpr_int32 block_read = 0; gpr_uint32 block_read = 0;
printf("Starting test: detached while reading\n"); printf("Starting test: detached while reading\n");
setup_test(0); setup_test(0);
/* Start a write. */ /* Start a write. */

@ -190,7 +190,7 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) {
census_ht* ht = census_ht_create(&opt); census_ht* ht = census_ht_create(&opt);
char key_str[1000][GPR_LTOA_MIN_BUFSIZE]; char key_str[1000][GPR_LTOA_MIN_BUFSIZE];
gpr_uint64 val = 0; gpr_uint64 val = 0;
int i = 0; unsigned i = 0;
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {
census_ht_key key; census_ht_key key;
key.ptr = key_str[i]; key.ptr = key_str[i];

@ -43,7 +43,8 @@ static void join_host_port_expect(const char *host, int port,
char *buf; char *buf;
int len; int len;
len = gpr_join_host_port(&buf, host, port); len = gpr_join_host_port(&buf, host, port);
GPR_ASSERT(strlen(expected) == len); GPR_ASSERT(len >= 0);
GPR_ASSERT(strlen(expected) == (size_t)len);
GPR_ASSERT(strcmp(expected, buf) == 0); GPR_ASSERT(strcmp(expected, buf) == 0);
gpr_free(buf); gpr_free(buf);
} }

@ -103,10 +103,10 @@ static void test_slice_new_with_len_returns_something_sensible(void) {
GPR_ASSERT(do_nothing_with_len_1_calls == 1); GPR_ASSERT(do_nothing_with_len_1_calls == 1);
} }
static void test_slice_sub_works(int length) { static void test_slice_sub_works(unsigned length) {
gpr_slice slice; gpr_slice slice;
gpr_slice sub; gpr_slice sub;
int i, j, k; unsigned i, j, k;
LOG_TEST_NAME(); LOG_TEST_NAME();
gpr_log(GPR_INFO, "length=%d", length); gpr_log(GPR_INFO, "length=%d", length);
@ -212,7 +212,7 @@ static void test_slice_from_copied_string_works(void) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int length; unsigned length;
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
test_slice_malloc_returns_something_sensible(); test_slice_malloc_returns_something_sensible();
test_slice_new_returns_something_sensible(); test_slice_new_returns_something_sensible();

@ -214,7 +214,7 @@ static void test_pluck(void) {
grpc_event *ev; grpc_event *ev;
grpc_completion_queue *cc; grpc_completion_queue *cc;
void *tags[128]; void *tags[128];
int i, j; unsigned i, j;
int on_finish_called = 0; int on_finish_called = 0;
LOG_TEST(); LOG_TEST();

@ -94,7 +94,7 @@ void decode_suite(char ext, gpr_timespec (*answer)(long x)) {
long test_vals[] = {1, 12, 123, 1234, 12345, 123456, long test_vals[] = {1, 12, 123, 1234, 12345, 123456,
1234567, 12345678, 123456789, 98765432, 9876543, 987654, 1234567, 12345678, 123456789, 98765432, 9876543, 987654,
98765, 9876, 987, 98, 9}; 98765, 9876, 987, 98, 9};
int i; unsigned i;
char *input; char *input;
for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) { for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) {
gpr_asprintf(&input, "%ld%c", test_vals[i], ext); gpr_asprintf(&input, "%ld%c", test_vals[i], ext);

@ -61,7 +61,7 @@ int main(int argc, char **argv) {
gpr_slice test_slice_3 = gpr_slice_malloc(3); gpr_slice test_slice_3 = gpr_slice_malloc(3);
gpr_slice test_slice_4 = gpr_slice_malloc(4); gpr_slice test_slice_4 = gpr_slice_malloc(4);
char x; char x;
int i; unsigned i;
grpc_stream_op_buffer buf; grpc_stream_op_buffer buf;
grpc_stream_op_buffer buf2; grpc_stream_op_buffer buf2;

@ -913,7 +913,7 @@ static const size_t interesting_message_lengths[] = {1, 100, 10000,
100000, 1000000, }; 100000, 1000000, };
void grpc_transport_end2end_tests(grpc_transport_test_config *config) { void grpc_transport_end2end_tests(grpc_transport_test_config *config) {
int i; unsigned i;
g_metadata_context = grpc_mdctx_create(); g_metadata_context = grpc_mdctx_create();

Loading…
Cancel
Save