]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix some silent issues that were highlighted by "infer"
authorMike Brady <mikebrady@eircom.net>
Sun, 3 Sep 2017 14:08:13 +0000 (15:08 +0100)
committerMike Brady <mikebrady@eircom.net>
Sun, 3 Sep 2017 14:08:13 +0000 (15:08 +0100)
alac.c
common.c
rtsp.c
shairport.c

diff --git a/alac.c b/alac.c
index c814ee3f0ca5077025650c97ced62c27ce421580..d8b6ac9ce93781ef49bcad34f7eedee6a48bddcb 100644 (file)
--- a/alac.c
+++ b/alac.c
@@ -998,12 +998,13 @@ void alac_decode_frame(alac_file *alac, unsigned char *inbuffer, void *outbuffer
 
 alac_file *alac_create(int samplesize, int numchannels) {
   alac_file *newfile = malloc(sizeof(alac_file));
-
-  memset(newfile, 0, sizeof(alac_file));
-
-  newfile->samplesize = samplesize;
-  newfile->numchannels = numchannels;
-  newfile->bytespersample = (samplesize / 8) * numchannels;
-
+  if (newfile) {
+    memset(newfile, 0, sizeof(alac_file));
+    newfile->samplesize = samplesize;
+    newfile->numchannels = numchannels;
+    newfile->bytespersample = (samplesize / 8) * numchannels;
+  } else {
+    fprintf(stderr, "FIXME: can not allocate memory for a new file in alac_cxreate."); 
+  }
   return newfile;
 }
index 08243fb3bca73d2e600882ebd545950021a6cfef..8e747b43c02ca375cad7b8ec78c03caa4aa5d91b 100644 (file)
--- a/common.c
+++ b/common.c
@@ -767,22 +767,26 @@ char *str_replace(const char *string, const char *substr, const char *replacemen
     return strdup(string);
   newstr = strdup(string);
   head = newstr;
-  while ((tok = strstr(head, substr))) {
-    oldstr = newstr;
-    newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
-    /*failed to alloc mem, free old string and return NULL */
-    if (newstr == NULL) {
+  if (head) {
+    while ((tok = strstr(head, substr))) {
+      oldstr = newstr;
+      newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
+      /*failed to alloc mem, free old string and return NULL */
+      if (newstr == NULL) {
+        free(oldstr);
+        return NULL;
+      }
+      memcpy(newstr, oldstr, tok - oldstr);
+      memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
+      memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
+             strlen(oldstr) - strlen(substr) - (tok - oldstr));
+      memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
+      /* move back head right after the last replacement */
+      head = newstr + (tok - oldstr) + strlen(replacement);
       free(oldstr);
-      return NULL;
     }
-    memcpy(newstr, oldstr, tok - oldstr);
-    memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
-    memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
-           strlen(oldstr) - strlen(substr) - (tok - oldstr));
-    memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
-    /* move back head right after the last replacement */
-    head = newstr + (tok - oldstr) + strlen(replacement);
-    free(oldstr);
+  } else {
+    die("failed to allocate memory in str_replace.");
   }
   return newstr;
 }
@@ -832,10 +836,14 @@ int ranarraynext;
 
 void ranarrayinit() {
   ranarray = (uint64_t *)malloc(ranarraylength * sizeof(uint64_t));
-  int i;
-  for (i = 0; i < ranarraylength; i++)
-    ranarray[i] = r64u();
-  ranarraynext = 0;
+  if (ranarray) {
+    int i;
+    for (i = 0; i < ranarraylength; i++)
+      ranarray[i] = r64u();
+    ranarraynext = 0;
+  } else {
+    die("failed to allocate space for the ranarray.");
+  }
 }
 
 uint64_t ranarrayval() {
diff --git a/rtsp.c b/rtsp.c
index c0e348117c55667ed04a0e6756e97687335e07eb..3a6612232f5fdcddc5a2a16037fd74e666de1426 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -252,8 +252,12 @@ void rtsp_request_shutdown_stream(void) {
 static int nconns = 0;
 static void track_thread(rtsp_conn_info *conn) {
   conns = realloc(conns, sizeof(rtsp_conn_info *) * (nconns + 1));
-  conns[nconns] = conn;
-  nconns++;
+  if (conns) {
+    conns[nconns] = conn;
+    nconns++;
+  } else {
+    die("could not reallocate memnory for \"conns\" in rtsp.c.");
+  }
 }
 
 static void cleanup_threads(void) {
@@ -329,8 +333,12 @@ static void msg_retain(rtsp_message *msg) {
 
 static rtsp_message *msg_init(void) {
   rtsp_message *msg = malloc(sizeof(rtsp_message));
-  memset(msg, 0, sizeof(rtsp_message));
-  msg->referenceCount = 1; // from now on, any access to this must be protected with the lock
+  if (msg) {
+    memset(msg, 0, sizeof(rtsp_message));
+    msg->referenceCount = 1; // from now on, any access to this must be protected with the lock
+  } else {
+    die("can not allocate memory for an rtsp_message.");
+  }
   return msg;
 }
 
index 83dd3fc13aef503c682bd28d72dee0274192686e..613b15ec050f359dc7b5a5c6dd00a7eb2f0cef5b 100644 (file)
@@ -971,6 +971,8 @@ int main(int argc, char **argv) {
   char *basec = strdup(argv[0]);
   char *bname = basename(basec);
   appName = strdup(bname);
+  if (appName==NULL)
+    die("can not allocate memory for the app name!");
   free(basec);
 
   // set defaults