summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2011-11-20 16:48:16 -0600
committerDan McGee <dpmcgee@gmail.com>2011-11-20 16:48:16 -0600
commit36204b1a6e611f44890b5a5d8faa303f3ace251d (patch)
tree91d7392850c86c7e37262af1659f1f31c2111227
parenta17dd711cbe5b2b2742faefaf710414e21175f12 (diff)
downloadonkyocontrol-36204b1a6e611f44890b5a5d8faa303f3ace251d.tar.gz
onkyocontrol-36204b1a6e611f44890b5a5d8faa303f3ace251d.zip
Small code cleanups
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r--command.c2
-rw-r--r--onkyo.c2
-rw-r--r--receiver.c4
-rw-r--r--util.c2
4 files changed, 8 insertions, 2 deletions
diff --git a/command.c b/command.c
index 933540e..69457b3 100644
--- a/command.c
+++ b/command.c
@@ -78,6 +78,8 @@ static int cmd_attempt(struct receiver *rcvr,
sprintf(fullcmd, "%s%s", cmd->prefix, arg);
q = malloc(sizeof(struct cmdqueue));
+ if(!q)
+ return -1;
q->hash = hash_sdbm(fullcmd);
q->cmd = fullcmd;
q->next = NULL;
diff --git a/onkyo.c b/onkyo.c
index 90cc983..73e2e92 100644
--- a/onkyo.c
+++ b/onkyo.c
@@ -115,6 +115,8 @@ static int open_connection(int fd)
if(!ptr) {
ptr = calloc(1, sizeof(struct conn));
+ if(!ptr)
+ return -1;
}
if(!ptr->recv_buf) {
ptr->recv_buf = calloc(BUF_SIZE, sizeof(char));
diff --git a/receiver.c b/receiver.c
index d568a4b..6269458 100644
--- a/receiver.c
+++ b/receiver.c
@@ -82,10 +82,12 @@ static char *next_rcvr_command(struct receiver *rcvr)
*/
int rcvr_send_command(struct receiver *rcvr)
{
+ char *cmd;
+
if(!rcvr->queue)
return -1;
- char *cmd = next_rcvr_command(rcvr);
+ cmd = next_rcvr_command(rcvr);
if(cmd) {
ssize_t retval;
size_t cmdsize = strlen(START_SEND) + strlen(cmd)
diff --git a/util.c b/util.c
index b842d31..ffe0258 100644
--- a/util.c
+++ b/util.c
@@ -80,9 +80,9 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
unsigned long hash_sdbm(const char *str)
{
unsigned long hash = 0;
+ int c;
if(!str)
return hash;
- int c;
while((c = *str++))
hash = c + (hash << 6) + (hash << 16) - hash;