Fix some silent issues that were highlighted by "infer"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user