>From c3351342a0d23af702bc324985cd86fc3cacf63d Mon Sep 17 00:00:00 2001
From: Jef Driesen <jefdriesen@users.sourceforge.net>
Date: Fri, 31 Oct 2014 22:40:34 +0100
Subject: [PATCH 3/3] Fix pointer casts.

---
 src/suunto_eonsteel.c        | 20 +++++++++++---------
 src/suunto_eonsteel_parser.c | 34 +++++++++++++++++-----------------
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c
index 0214c3b..426f310 100644
--- a/src/suunto_eonsteel.c
+++ b/src/suunto_eonsteel.c
@@ -240,7 +240,9 @@ static int send_cmd(suunto_eonsteel_device_t *eon,
 	put_le32(len, buf+10);
 
 	// .. followed by actual data
-	memcpy(buf+14, buffer, len);
+	if (len) {
+		memcpy(buf+14, buffer, len);
+	}
 
 	rc = libusb_interrupt_transfer(eon->handle, OutEndpoint, buf, sizeof(buf), &transferred, 5000);
 	if (rc < 0)
@@ -316,7 +318,7 @@ static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buf
 // debug("lookup", result, rc);
 
 	rc = send_receive(eon, FILE_STAT_CMD,
-		0, "",
+		0, NULL,
 		sizeof(result), result);
 	if (rc < 0)
 		return report_error("unable to stat %s", filename);
@@ -361,7 +363,7 @@ static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buf
 	}
 
 	rc = send_receive(eon, FILE_CLOSE_CMD,
-		0, "",
+		0, NULL,
 		sizeof(result), result);
 	if (rc < 0)
 		report_error("cmd 0510 failed");
@@ -380,7 +382,7 @@ static struct directory_entry *parse_dirent(int nr, const unsigned char *p, int
 	while (len > 8) {
 		unsigned int type = array_uint32_le(p);
 		unsigned int namelen = array_uint32_le(p+4);
-		const unsigned char *name = p+8;
+		const char *name = (const char *)p+8;
 		struct directory_entry *entry;
 
 		if (namelen + 8 + 1 > len || name[namelen] != 0) {
@@ -407,7 +409,7 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
 
 	*res = NULL;
 	put_le32(0, cmd);
-	strcpy(cmd+4, dive_directory);
+	strcpy((char *)cmd+4, dive_directory);
 	cmdlen = 4+strlen(dive_directory)+1;
 	rc = send_receive(eon, DIR_LOOKUP_CMD,
 		cmdlen, cmd,
@@ -420,7 +422,7 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
 		unsigned int nr, last;
 
 		rc = send_receive(eon, READDIR_CMD,
-			0, "",
+			0, NULL,
 			sizeof(result), result);
 		if (rc < 0)
 			return report_error("readdir failed");
@@ -436,7 +438,7 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
 	}
 
 	rc = send_receive(eon, DIR_CLOSE_CMD,
-		0, "",
+		0, NULL,
 		sizeof(result), result);
 	if (rc < 0)
 		report_error("dir close failed");
@@ -461,7 +463,7 @@ static int initialize_eonsteel(suunto_eonsteel_device_t *eon)
 			break;
 	}
 
-	if (send_cmd(eon, INIT_CMD, INIT_LEN, INIT_DATA))
+	if (send_cmd(eon, INIT_CMD, INIT_LEN, (const unsigned char *)INIT_DATA))
 		return report_error("Failed to send initialization command");
 	if (receive_data(eon, buf, sizeof(buf)) < 0)
 		return report_error("Failed to receive initial reply");
@@ -574,7 +576,7 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac
 			// Reset the membuffer, put the 4-byte length at the head.
 			dc_buffer_clear(file);
 			put_le32(time, buf);
-			dc_buffer_append(file, buf, 4);
+			dc_buffer_append(file, (unsigned char *)buf, 4);
 
 			// Then read the filename into the rest of the buffer
 			rc = read_file(eon, pathname, file);
diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c
index f86f46c..d0c1483 100644
--- a/src/suunto_eonsteel_parser.c
+++ b/src/suunto_eonsteel_parser.c
@@ -98,7 +98,7 @@ static void debug_text(const char *name, const char *buf, int len)
 			putchar('\\');
 			putchar('n');
 		} else {
-			static const char hex[16]="0123456789abcdef";
+			static const char hex[]="0123456789abcdef";
 			putchar('\\');
 			putchar('x');
 			putchar(hex[c>>4]);
@@ -108,7 +108,7 @@ static void debug_text(const char *name, const char *buf, int len)
 	printf("\nend of text\n");
 }
 
-typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const void *data, int len, void *user);
+typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user);
 
 static int record_type(suunto_eonsteel_parser_t *eon, unsigned short type, const char *name, int namelen)
 {
@@ -130,7 +130,7 @@ static int record_type(suunto_eonsteel_parser_t *eon, unsigned short type, const
 
 		if (len < 5 || name[0] != '<' || name[4] != '>')
 			return report_error("Unexpected type description: %.*s", len, name);
-		p = malloc(len-4);
+		p = (char *) malloc(len-4);
 		if (!p)
 			return report_error("out of memory");
 		memcpy(p, name+5, len-5);
@@ -168,7 +168,7 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
 
 	// First two bytes: zero and text length
 	if (p[0]) {
-		debug("next", p, 8);
+		debug("next", (const char *)p, 8);
 		return report_error("Bad dive entry (%02x)", p[0]);
 	}
 	textlen = p[1];
@@ -186,16 +186,16 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
 
 	if (*name != '<') {
 		fflush(NULL);
-		debug("bad", p, 16);
+		debug("bad", (const char *)p, 16);
 		exit(1);
 	}
 
-	record_type(eon, type, name, textlen-3);
+	record_type(eon, type, (const char *)name, textlen-3);
 
 	end = data;
 	last = data;
 	while (end < one_past_end && *end) {
-		const char *begin = end;
+		const char *begin = (const char *)end;
 		unsigned int type = *end++;
 		unsigned int len;
 		if (type == 0xff) {
@@ -207,13 +207,13 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
 		// I've never actually seen this case yet..
 		// Just assuming from the other cases.
 		if (len == 0xff) {
-			debug("len-ff", end, 8);
+			debug("len-ff", (const char *)end, 8);
 			len = array_uint32_le(end);
 			end += 4;
 		}
 
 		if (type > MAXTYPE || !eon->type_desc[type].desc) {
-			debug("last", last, 16);
+			debug("last", (const char *)last, 16);
 			debug("this", begin, 16);
 		} else {
 			rc = callback(type, eon->type_desc+type, end, len, user);
@@ -221,7 +221,7 @@ static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p,
 				return rc;
 		}
 
-		last = begin;
+		last = (const unsigned char *)begin;
 		end += len;
 	}
 
@@ -320,9 +320,9 @@ static void sample_cylinder_pressure(struct sample_data *info, unsigned char idx
 	if (info->callback) info->callback(DC_SAMPLE_PRESSURE, sample, info->userdata);
 }
 
-static int traverse_samples(unsigned short type, const struct type_desc *desc, const void *data, int len, void *user)
+static int traverse_samples(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user)
 {
-	struct sample_data *info = user;
+	struct sample_data *info = (struct sample_data *)user;
 
 	switch (type) {
 	case 0x0001: // group: time in first word, depth in second
@@ -347,7 +347,7 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c
 static dc_status_t
 suunto_eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
 {
-	suunto_eonsteel_parser_t *eon = (void *)abstract;
+	suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)abstract;
 	struct sample_data data = { eon, callback, userdata, 0 };
 
 	traverse_data(eon, traverse_samples, &data);
@@ -455,9 +455,9 @@ static void add_gas_he(suunto_eonsteel_parser_t *eon, unsigned char he)
 	eon->cache.initialized |= 1 << DC_FIELD_GASMIX;
 }
 
-static int traverse_fields(unsigned short type, const struct type_desc *desc, const void *data, int len, void *user)
+static int traverse_fields(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user)
 {
-	suunto_eonsteel_parser_t *eon = user;
+	suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)user;
 
 	switch (type) {
 	case 0x0001: // group: time in first word, depth in second
@@ -499,7 +499,7 @@ static void initialize_field_caches(suunto_eonsteel_parser_t *eon)
 static dc_status_t
 suunto_eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, unsigned int size)
 {
-	suunto_eonsteel_parser_t *eon = (void *)parser;
+	suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)parser;
 	memset(eon->type_desc, 0, sizeof(eon->type_desc));
 	initialize_field_caches(eon);
 	return DC_STATUS_SUCCESS;
@@ -529,7 +529,7 @@ suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned
 	if (out == NULL)
 		return DC_STATUS_INVALIDARGS;
 
-	eon = calloc(1, sizeof(*eon));
+	eon = (suunto_eonsteel_parser_t *)calloc(1, sizeof(*eon));
 	parser_init(&eon->base, context, &suunto_eonsteel_parser_vtable);
 	*out = &eon->base;
 
-- 
1.9.1

