diff options
author | Dan McGee <dpmcgee@gmail.com> | 2015-04-07 11:47:59 -0500 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2015-04-07 11:47:59 -0500 |
commit | 347ae48021e32cba1bac8459cb36f88626268883 (patch) | |
tree | 87cec169455e57db07e3d6b5cdf2f30095267552 | |
parent | 4bc588efc4a92dcf0e76d87bc730699270d6f178 (diff) | |
download | onkyocontrol-master.tar.gz onkyocontrol-master.zip |
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r-- | onkyo.c | 12 | ||||
-rw-r--r-- | onkyo.h | 1 | ||||
-rw-r--r-- | receiver.c | 18 | ||||
-rw-r--r-- | util.c | 2 |
4 files changed, 19 insertions, 14 deletions
@@ -406,7 +406,7 @@ static int open_serial_device(const char *path) /* canonical input mode- end read at a line descriptor */ newtio.c_lflag = ICANON; /* add the Onkyo-used EOF char to allow canonical read */ - newtio.c_cc[VEOL] = END_RECV[strlen(END_RECV) - 1]; + newtio.c_cc[VEOL] = (cc_t)END_RECV[strlen(END_RECV) - 1]; /* clean the line and activate the settings */ ret = tcflush(rcvr->fd, TCIOFLUSH); @@ -659,7 +659,7 @@ static int process_input(struct conn *c) const char * const end_pos = &(c->recv_buf[BUF_SIZE]); int ret = 0; - int count; + ssize_t count; /* * Picture time! Let's get overly verbose since we don't do this @@ -687,6 +687,7 @@ static int process_input(struct conn *c) while(count > 0) { if(*c->recv_buf_pos == '\n') { int processret = 0; + size_t remaining; struct receiver *r; /* We have a newline. This means we should have a full command * and can attempt to interpret it. */ @@ -705,10 +706,11 @@ static int process_input(struct conn *c) } /* now move our remaining buffer to the start of our buffer */ c->recv_buf_pos++; - memmove(c->recv_buf, c->recv_buf_pos, count - 1); + remaining = (size_t)count - 1; + memmove(c->recv_buf, c->recv_buf_pos, remaining); c->recv_buf_pos = c->recv_buf; - memset(&(c->recv_buf_pos[count - 1]), 0, - end_pos - &(c->recv_buf_pos[count - 1])); + memset(&(c->recv_buf_pos[remaining]), 0, + end_pos - &(c->recv_buf_pos[remaining])); if(ret == -2) break; } @@ -41,6 +41,7 @@ enum power { MAIN_POWER = (1 << 0), ZONE2_POWER = (1 << 1), ZONE3_POWER = (1 << 2), + POWER_ON = -1, }; /** Keep track of two paired file descriptors */ @@ -127,7 +127,7 @@ int rcvr_send_command(struct receiver *rcvr) * @param status the status string returned by the receiver * @return the read size on success, -1 on failure */ -static int rcvr_handle_status(int serialfd, char **status) +static ssize_t rcvr_handle_status(int serialfd, char **status) { ssize_t retval; char buf[BUF_SIZE]; @@ -141,9 +141,10 @@ static int rcvr_handle_status(int serialfd, char **status) buf[retval] = '\0'; /* return the status message if asked for */ if(status) { - *status = malloc((retval + 1) * sizeof(char)); + size_t alloc_size = (size_t)retval + 1; + *status = malloc(alloc_size * sizeof(char)); if(*status) - memcpy(*status, buf, retval + 1); + memcpy(*status, buf, alloc_size); } return retval; } @@ -369,7 +370,7 @@ static void update_power_status(struct receiver *rcvr, int zone, int value); * @param status the receiver status message to make human readable * @return 0 on normal status, -1 on parse errors */ -static int parse_status(struct receiver *rcvr, int size, char *status) +static int parse_status(struct receiver *rcvr, size_t size, char *status) { unsigned long hashval; char buf[BUF_SIZE]; @@ -553,17 +554,18 @@ static void update_power_status(struct receiver *rcvr, int zone, int value) */ int process_incoming_message(struct receiver *rcvr, int logfd) { - int size, ret; + int ret; + ssize_t size; char *status = NULL; /* get the output from the receiver */ size = rcvr_handle_status(rcvr->fd, &status); - if(size != -1) { + if(size >= 0) { /* log the message if we have a logfd */ if(logfd > 0) - xwrite(logfd, status, size + 1); + xwrite(logfd, status, (size_t)size + 1); /* parse the return and output a status message */ - ret = parse_status(rcvr, size, status); + ret = parse_status(rcvr, (size_t)size, status); if(!ret) rcvr->msgs_received++; } else { @@ -82,7 +82,7 @@ unsigned long hash_sdbm(const char *str) if(!str) return hash; while((c = *str++)) - hash = c + hash * 65599; + hash = (unsigned int)c + hash * 65599; return hash; } |