summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Steinert <mike.steinert@gmail.com>2012-05-16 10:42:44 -0600
committerMichael Steinert <mike.steinert@gmail.com>2012-05-17 11:44:45 -0600
commit162fc19f4d896c3db862f1da303823dcbe9780ec (patch)
tree36656320e462ca62575afa30931a7301162732f8
parenta4881f40d2862f193cc38f9759564370004215c4 (diff)
downloadrabbitmq-c-github-ask-162fc19f4d896c3db862f1da303823dcbe9780ec.tar.gz
Fix compiler warnings (checked clang & gcc)
Signed-off-by: Michael Steinert <mike.steinert@gmail.com>
-rw-r--r--examples/amqp_producer.c2
-rw-r--r--examples/utils.c2
-rw-r--r--librabbitmq/amqp_api.c5
-rw-r--r--librabbitmq/amqp_connection.c2
-rw-r--r--librabbitmq/amqp_private.h9
-rw-r--r--librabbitmq/amqp_socket.c2
-rw-r--r--librabbitmq/amqp_table.c2
-rw-r--r--tests/test_parse_url.c2
-rw-r--r--tests/test_tables.c46
-rw-r--r--tools/common.c9
-rw-r--r--tools/consume.c2
-rw-r--r--tools/declare_queue.c2
-rw-r--r--tools/delete_queue.c2
-rw-r--r--tools/get.c2
-rw-r--r--tools/publish.c2
15 files changed, 47 insertions, 44 deletions
diff --git a/examples/amqp_producer.c b/examples/amqp_producer.c
index c149a72..22ac6fa 100644
--- a/examples/amqp_producer.c
+++ b/examples/amqp_producer.c
@@ -57,7 +57,7 @@ static void send_batch(amqp_connection_state_t conn,
char message[256];
amqp_bytes_t message_bytes;
- for (i = 0; i < sizeof(message); i++) {
+ for (i = 0; i < (int)sizeof(message); i++) {
message[i] = i & 0xff;
}
diff --git a/examples/utils.c b/examples/utils.c
index 5adbc2c..871fc2a 100644
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -135,7 +135,7 @@ void amqp_dump(void const *buffer, size_t len) {
int chs[16];
int oldchs[16];
int showed_dots = 0;
- int i;
+ size_t i;
for (i = 0; i < len; i++) {
int ch = buf[i];
diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c
index 4e0bb3e..b4effec 100644
--- a/librabbitmq/amqp_api.c
+++ b/librabbitmq/amqp_api.c
@@ -143,9 +143,8 @@ int amqp_basic_publish(amqp_connection_state_t state,
return res;
body_offset = 0;
- while (1) {
- int remaining = body.len - body_offset;
- assert(remaining >= 0);
+ while (body_offset < body.len) {
+ size_t remaining = body.len - body_offset;
if (remaining == 0)
break;
diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c
index 35d1e15..9289316 100644
--- a/librabbitmq/amqp_connection.c
+++ b/librabbitmq/amqp_connection.c
@@ -51,7 +51,7 @@
#define ENFORCE_STATE(statevec, statenum) \
{ \
amqp_connection_state_t _check_state = (statevec); \
- int _wanted_state = (statenum); \
+ size_t _wanted_state = (statenum); \
if (_check_state->state != _wanted_state) \
amqp_abort("Programming error: invalid AMQP connection state: expected %d, got %d", \
_wanted_state, \
diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h
index 7cfb65c..27ba3dd 100644
--- a/librabbitmq/amqp_private.h
+++ b/librabbitmq/amqp_private.h
@@ -57,6 +57,14 @@
#define ERROR_BAD_AMQP_URL 8
#define ERROR_MAX 8
+/* GCC attributes */
+#if __GNUC__ > 2 | (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+#define AMQP_NORETURN \
+ __attribute__ ((__noreturn__))
+#else
+#define AMQP_NORETURN
+#endif
+
extern char *amqp_os_error_string(int err);
#include "socket.h"
@@ -253,6 +261,7 @@ static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset,
}
}
+AMQP_NORETURN
extern void amqp_abort(const char *fmt, ...);
#endif
diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c
index 157aec8..60bb545 100644
--- a/librabbitmq/amqp_socket.c
+++ b/librabbitmq/amqp_socket.c
@@ -372,7 +372,7 @@ static int amqp_login_inner(amqp_connection_state_t state,
{
int res;
amqp_method_t method;
- uint32_t server_frame_max;
+ int server_frame_max;
uint16_t server_channel_max;
uint16_t server_heartbeat;
diff --git a/librabbitmq/amqp_table.c b/librabbitmq/amqp_table.c
index b3b33f3..ec098ba 100644
--- a/librabbitmq/amqp_table.c
+++ b/librabbitmq/amqp_table.c
@@ -413,7 +413,7 @@ int amqp_table_entry_cmp(void const *entry1, void const *entry2) {
amqp_table_entry_t const *p2 = (amqp_table_entry_t const *) entry2;
int d;
- int minlen;
+ size_t minlen;
minlen = p1->key.len;
if (p2->key.len < minlen) minlen = p2->key.len;
diff --git a/tests/test_parse_url.c b/tests/test_parse_url.c
index 4870e12..a4c5f09 100644
--- a/tests/test_parse_url.c
+++ b/tests/test_parse_url.c
@@ -103,7 +103,7 @@ static void parse_fail(const char *url)
free(s);
}
-int main(int argc, char **argv)
+int main(void)
{
/* From the spec */
parse_success("amqp://user:pass@host:10000/vhost", "user", "pass",
diff --git a/tests/test_tables.c b/tests/test_tables.c
index a01a9b0..be2f7ae 100644
--- a/tests/test_tables.c
+++ b/tests/test_tables.c
@@ -52,7 +52,9 @@ void die(const char *fmt, ...)
abort();
}
+#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
+#endif
static void dump_indent(int indent, FILE *out)
{
@@ -122,7 +124,7 @@ static void dump_value(int indent, amqp_field_value_t v, FILE *out)
case AMQP_FIELD_KIND_BYTES:
fputc(' ', out);
- for (i = 0; i < v.value.bytes.len; i++)
+ for (i = 0; i < (int)v.value.bytes.len; i++)
fprintf(out, "%02x", ((char *) v.value.bytes.bytes)[i]);
fputc('\n', out);
@@ -401,21 +403,14 @@ static void test_table_codec(FILE *out)
#define CHUNK_SIZE 4096
-static int compare_files(const char *f1, const char *f2)
+static int compare_files(FILE *f1_in, FILE *f2_in)
{
- FILE *f1_in;
- FILE *f2_in;
char f1_buf[CHUNK_SIZE];
char f2_buf[CHUNK_SIZE];
int res;
- f1_in = fopen(f1, "r");
- if (f1_in == NULL)
- die("opening %s: %s", f1, strerror(errno));
-
- f2_in = fopen(f2, "r");
- if (f2_in == NULL)
- die("opening %s: %s", f2, strerror(errno));
+ rewind(f1_in);
+ rewind(f2_in);
for (;;) {
size_t f1_got = fread(f1_buf, 1, CHUNK_SIZE, f1_in);
@@ -427,45 +422,44 @@ static int compare_files(const char *f1, const char *f2)
if (f1_got < CHUNK_SIZE || f2_got < CHUNK_SIZE) {
if (f1_got != f2_got)
- res = (f1_got < f2_got ? -1 : 1);
+ res = (f1_got < f2_got ? -1 : 1);
break;
}
}
- fclose(f1_in);
- fclose(f2_in);
-
return res;
}
const char *expected_file_name = "tests/test_tables.expected";
-int main(int argc, char **argv)
+int main(void)
{
char *srcdir = getenv("srcdir");
- char out_path[L_tmpnam];
- FILE *out = fopen(tmpnam(out_path), "w");
+ FILE *out, *expected = NULL;
char *expected_path;
+ out = tmpfile();
if (out == NULL)
- die("opening %s: %s", out_path, strerror(errno));
+ die("failed to create temporary file: %s", strerror(errno));
test_table_codec(out);
fprintf(out, "----------\n");
test_dump_value(out);
- fclose(out);
-
if (srcdir == NULL)
- die("'srcdir' environment variable not defined");
+ srcdir = "tests";
expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2);
sprintf(expected_path, "%s/%s", srcdir, expected_file_name);
- if (compare_files(expected_path, out_path))
- die("output file did not have expected contents; see %s", out_path);
+ expected = fopen(expected_path, "r");
+ if (!expected)
+ die("failed to open %s: %s", expected_path, strerror(errno));
+
+ if (compare_files(expected, out))
+ die("output file did not have expected contents");
- if (remove(out_path))
- die("deleting %s: %s", out_path, strerror(errno));
+ fclose(out);
+ fclose(expected);
return 0;
}
diff --git a/tools/common.c b/tools/common.c
index 71ae07d..2c248b9 100644
--- a/tools/common.c
+++ b/tools/common.c
@@ -30,7 +30,7 @@
* ***** END LICENSE BLOCK *****
*/
-#ifndef HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -181,7 +181,7 @@ struct poptOption connect_options[] = {
"the username to login with", "username"},
{"password", 0, POPT_ARG_STRING, &amqp_password, 0,
"the password to login with", "password"},
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
static void init_connection_info(struct amqp_connection_info *ci)
@@ -331,7 +331,8 @@ amqp_bytes_t read_all(int fd)
bytes.len = 0;
for (;;) {
- ssize_t res = read(fd, bytes.bytes+bytes.len, space-bytes.len);
+ ssize_t res = read(fd, (char *)bytes.bytes + bytes.len,
+ space-bytes.len);
if (res == 0)
break;
@@ -360,7 +361,7 @@ void write_all(int fd, amqp_bytes_t data)
die_errno(errno, "write");
data.len -= res;
- data.bytes += res;
+ data.bytes = (char *)data.bytes + res;
}
}
diff --git a/tools/consume.c b/tools/consume.c
index 9c53606..4f79889 100644
--- a/tools/consume.c
+++ b/tools/consume.c
@@ -182,7 +182,7 @@ int main(int argc, const char **argv)
"stop consuming after this many messages are consumed",
"limit"},
POPT_AUTOHELP
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
opts = process_options(argc, argv, options,
diff --git a/tools/declare_queue.c b/tools/declare_queue.c
index 5c6a2bd..fc9524c 100644
--- a/tools/declare_queue.c
+++ b/tools/declare_queue.c
@@ -54,7 +54,7 @@ int main(int argc, const char **argv)
{"durable", 'd', POPT_ARG_VAL, &durable, 1,
"declare a durable queue", NULL},
POPT_AUTOHELP
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
process_all_options(argc, argv, options);
diff --git a/tools/delete_queue.c b/tools/delete_queue.c
index d9594e9..4577d74 100644
--- a/tools/delete_queue.c
+++ b/tools/delete_queue.c
@@ -57,7 +57,7 @@ int main(int argc, const char **argv)
{"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1,
"do not delete unless queue is empty", NULL},
POPT_AUTOHELP
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
process_all_options(argc, argv, options);
diff --git a/tools/get.c b/tools/get.c
index b3e0e81..3e536c7 100644
--- a/tools/get.c
+++ b/tools/get.c
@@ -62,7 +62,7 @@ int main(int argc, const char **argv)
{"queue", 'q', POPT_ARG_STRING, &queue, 0,
"the queue to consume from", "queue"},
POPT_AUTOHELP
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
process_all_options(argc, argv, options);
diff --git a/tools/publish.c b/tools/publish.c
index 08ae18a..f7e7e77 100644
--- a/tools/publish.c
+++ b/tools/publish.c
@@ -79,7 +79,7 @@ int main(int argc, const char **argv)
{"body", 'b', POPT_ARG_STRING, &body, 0,
"specify the message body", "body"},
POPT_AUTOHELP
- { NULL, 0, 0, NULL, 0 }
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
};
process_all_options(argc, argv, options);