Fixes issues found by scan-build in mpd.c and queue.c

This commit is contained in:
chme 2016-11-20 06:27:45 +01:00
parent 94a55d9fc9
commit a95da7966b
2 changed files with 40 additions and 20 deletions

View File

@ -437,17 +437,19 @@ mpd_add_mediainfo(struct evbuffer *evbuf, struct media_file_info *mfi, unsigned
mfi->genre, mfi->genre,
mfi->disc); mfi->disc);
if (pos_pl >= 0) if (ret >= 0 && pos_pl >= 0)
{ {
ret = evbuffer_add_printf(evbuf, ret = evbuffer_add_printf(evbuf,
"Pos: %d\n", "Pos: %d\n",
pos_pl); pos_pl);
if (ret >= 0)
{
ret = evbuffer_add_printf(evbuf, ret = evbuffer_add_printf(evbuf,
"Id: %d\n", "Id: %d\n",
item_id); item_id);
} }
}
return ret; return ret;
} }
@ -2039,12 +2041,16 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e
} }
if (strncmp(argv[1], "/", 1) == 0) if (strncmp(argv[1], "/", 1) == 0)
{
ret = snprintf(path, sizeof(path), "%s", argv[1]); ret = snprintf(path, sizeof(path), "%s", argv[1]);
}
else else
{
ret = snprintf(path, sizeof(path), "/%s", argv[1]); ret = snprintf(path, sizeof(path), "/%s", argv[1]);
if (ret >= sizeof(path))
{
ret = asprintf(errmsg, "Length of path exceeds the PATH_MAX value '%s'", argv[1]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
@ -2111,12 +2117,16 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char
} }
if (strncmp(argv[1], "/", 1) == 0) if (strncmp(argv[1], "/", 1) == 0)
{
ret = snprintf(path, sizeof(path), "%s", argv[1]); ret = snprintf(path, sizeof(path), "%s", argv[1]);
}
else else
{
ret = snprintf(path, sizeof(path), "/%s", argv[1]); ret = snprintf(path, sizeof(path), "/%s", argv[1]);
if (ret >= sizeof(path))
{
ret = asprintf(errmsg, "Length of path exceeds the PATH_MAX value '%s'", argv[1]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
@ -2241,12 +2251,16 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
} }
if (strncmp(argv[1], "/", 1) == 0) if (strncmp(argv[1], "/", 1) == 0)
{
ret = snprintf(path, sizeof(path), "%s", argv[1]); ret = snprintf(path, sizeof(path), "%s", argv[1]);
}
else else
{
ret = snprintf(path, sizeof(path), "/%s", argv[1]); ret = snprintf(path, sizeof(path), "/%s", argv[1]);
if (ret >= sizeof(path))
{
ret = asprintf(errmsg, "Length of path exceeds the PATH_MAX value '%s'", argv[1]);
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG;
} }
pli = db_pl_fetch_byvirtualpath(path); pli = db_pl_fetch_byvirtualpath(path);
@ -4276,7 +4290,7 @@ mpd_read_cb(struct bufferevent *bev, void *ctx)
// Split the read line into command name and arguments // Split the read line into command name and arguments
ret = mpd_parse_args(line, &argc, argv); ret = mpd_parse_args(line, &argc, argv);
if (ret != 0) if (ret != 0 || argc <= 0)
{ {
// Error handling for argument parsing error // Error handling for argument parsing error
DPRINTF(E_LOG, L_MPD, "Error parsing arguments for MPD message: %s\n", line); DPRINTF(E_LOG, L_MPD, "Error parsing arguments for MPD message: %s\n", line);

View File

@ -117,7 +117,7 @@ queue_new()
} }
/* /*
* Frees the given item and all linked items * Frees the given item and all linked (next) items
*/ */
static void static void
queue_items_free(struct queue_item *item) queue_items_free(struct queue_item *item)
@ -125,6 +125,11 @@ queue_items_free(struct queue_item *item)
struct queue_item *temp; struct queue_item *temp;
struct queue_item *next; struct queue_item *next;
if (!item)
return;
// Make the queue non-circular
if (item->prev)
item->prev->next = NULL; item->prev->next = NULL;
next = item; next = item;
@ -1194,6 +1199,7 @@ queueitem_make_byquery(struct query_params *qp)
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_PLAYER, "Error fetching results\n"); DPRINTF(E_LOG, L_PLAYER, "Error fetching results\n");
queue_items_free(item_tail);
return NULL; return NULL;
} }