mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-20 04:24:20 -04:00
[db] Coverity fixups
This commit is contained in:
parent
070866b41a
commit
d72958f1f7
95
src/db.c
95
src/db.c
@ -775,6 +775,20 @@ free_di(struct directory_info *di, int content_only)
|
|||||||
memset(di, 0, sizeof(struct directory_info));
|
memset(di, 0, sizeof(struct directory_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
free_wi(struct watch_info *wi, int content_only)
|
||||||
|
{
|
||||||
|
if (!wi)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free(wi->path);
|
||||||
|
|
||||||
|
if (!content_only)
|
||||||
|
free(wi);
|
||||||
|
else
|
||||||
|
memset(wi, 0, sizeof(struct watch_info));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
free_query_params(struct query_params *qp, int content_only)
|
free_query_params(struct query_params *qp, int content_only)
|
||||||
{
|
{
|
||||||
@ -2682,8 +2696,8 @@ db_query_fetch_string_sort(char **string, char **sortstring, struct query_params
|
|||||||
int
|
int
|
||||||
db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt = NULL;
|
||||||
char *query;
|
char *query = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!filter && !nstreams)
|
if (!filter && !nstreams)
|
||||||
@ -2698,17 +2712,16 @@ db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
|||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||||
return -1;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
|
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
|
||||||
|
|
||||||
ret = db_blocking_prepare_v2(query, -1, &stmt, NULL);
|
ret = db_blocking_prepare_v2(query, -1, &stmt, NULL);
|
||||||
sqlite3_free(query);
|
|
||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
||||||
return -1;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db_blocking_step(stmt);
|
ret = db_blocking_step(stmt);
|
||||||
@ -2719,8 +2732,7 @@ db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
|||||||
else
|
else
|
||||||
DPRINTF(E_LOG, L_DB, "Could not step: %s (%s)\n", sqlite3_errmsg(hdl), query);
|
DPRINTF(E_LOG, L_DB, "Could not step: %s (%s)\n", sqlite3_errmsg(hdl), query);
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nitems)
|
if (nitems)
|
||||||
@ -2733,9 +2745,16 @@ db_files_get_count(uint32_t *nitems, uint32_t *nstreams, const char *filter)
|
|||||||
; /* EMPTY */
|
; /* EMPTY */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
sqlite3_free(query);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (query)
|
||||||
|
sqlite3_free(query);
|
||||||
|
if (stmt)
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -6059,10 +6078,10 @@ queue_reshuffle(uint32_t item_id, int queue_version)
|
|||||||
int pos;
|
int pos;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
struct db_queue_item queue_item;
|
struct db_queue_item queue_item;
|
||||||
int *shuffle_pos;
|
int *shuffle_pos = NULL;
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
struct query_params qp;
|
struct query_params qp = { 0 };
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_DB, "Reshuffle queue after item with item-id: %d\n", item_id);
|
DPRINTF(E_DBG, L_DB, "Reshuffle queue after item with item-id: %d\n", item_id);
|
||||||
@ -6071,43 +6090,39 @@ queue_reshuffle(uint32_t item_id, int queue_version)
|
|||||||
query = sqlite3_mprintf("UPDATE queue SET shuffle_pos = pos, queue_version = %d;", queue_version);
|
query = sqlite3_mprintf("UPDATE queue SET shuffle_pos = pos, queue_version = %d;", queue_version);
|
||||||
ret = db_query_run(query, 1, 0);
|
ret = db_query_run(query, 1, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
if (item_id > 0)
|
if (item_id > 0)
|
||||||
{
|
{
|
||||||
pos = db_queue_get_pos(item_id, 0);
|
pos = db_queue_get_pos(item_id, 0);
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
pos++; // Do not reshuffle the base item
|
pos++; // Do not reshuffle the base item
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db_queue_get_count(&count);
|
ret = db_queue_get_count(&count);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
len = count - pos;
|
len = count - pos;
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_DB, "Reshuffle %d items off %" PRIu32 " total items, starting from pos %d\n", len, count, pos);
|
DPRINTF(E_DBG, L_DB, "Reshuffle %d items off %" PRIu32 " total items, starting from pos %d\n", len, count, pos);
|
||||||
|
|
||||||
shuffle_pos = malloc(len * sizeof(int));
|
CHECK_NULL(L_DB, shuffle_pos = malloc(len * sizeof(int)));
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
shuffle_pos[i] = i + pos;
|
shuffle_pos[i] = i + pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
shuffle_int(&shuffle_rng, shuffle_pos, len);
|
rng_shuffle_int(&shuffle_rng, shuffle_pos, len);
|
||||||
|
|
||||||
memset(&qp, 0, sizeof(struct query_params));
|
|
||||||
qp.filter = sqlite3_mprintf("pos >= %d", pos);
|
qp.filter = sqlite3_mprintf("pos >= %d", pos);
|
||||||
|
|
||||||
ret = queue_enum_start(&qp);
|
ret = queue_enum_start(&qp);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
goto error;
|
||||||
sqlite3_free(qp.filter);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((ret = queue_enum_fetch(&qp, &queue_item, 0)) == 0 && (queue_item.id > 0) && (i < len))
|
while ((ret = queue_enum_fetch(&qp, &queue_item, 0)) == 0 && (queue_item.id > 0) && (i < len))
|
||||||
@ -6124,12 +6139,18 @@ queue_reshuffle(uint32_t item_id, int queue_version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
db_query_end(&qp);
|
db_query_end(&qp);
|
||||||
sqlite3_free(qp.filter);
|
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
|
sqlite3_free(qp.filter);
|
||||||
|
free(shuffle_pos);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
sqlite3_free(qp.filter);
|
||||||
|
free(shuffle_pos);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -6216,7 +6237,7 @@ db_watch_delete_bywd(uint32_t wd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_delete_bypath(char *path)
|
db_watch_delete_bypath(const char *path)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "DELETE FROM inotify WHERE path = '%q';"
|
#define Q_TMPL "DELETE FROM inotify WHERE path = '%q';"
|
||||||
char *query;
|
char *query;
|
||||||
@ -6228,7 +6249,7 @@ db_watch_delete_bypath(char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_delete_bymatch(char *path)
|
db_watch_delete_bymatch(const char *path)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "DELETE FROM inotify WHERE path LIKE '%q/%%';"
|
#define Q_TMPL "DELETE FROM inotify WHERE path LIKE '%q/%%';"
|
||||||
char *query;
|
char *query;
|
||||||
@ -6316,12 +6337,12 @@ db_watch_get_byquery(struct watch_info *wi, char *query)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_get_bywd(struct watch_info *wi)
|
db_watch_get_bywd(struct watch_info *wi, int wd)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "SELECT * FROM inotify WHERE wd = %d;"
|
#define Q_TMPL "SELECT * FROM inotify WHERE wd = %d;"
|
||||||
char *query;
|
char *query;
|
||||||
|
|
||||||
query = sqlite3_mprintf(Q_TMPL, wi->wd);
|
query = sqlite3_mprintf(Q_TMPL, wd);
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||||
@ -6333,12 +6354,12 @@ db_watch_get_bywd(struct watch_info *wi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_get_bypath(struct watch_info *wi)
|
db_watch_get_bypath(struct watch_info *wi, const char *path)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "SELECT * FROM inotify WHERE path = '%q';"
|
#define Q_TMPL "SELECT * FROM inotify WHERE path = '%q';"
|
||||||
char *query;
|
char *query;
|
||||||
|
|
||||||
query = sqlite3_mprintf(Q_TMPL, wi->path);
|
query = sqlite3_mprintf(Q_TMPL, path);
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||||
@ -6350,7 +6371,7 @@ db_watch_get_bypath(struct watch_info *wi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_mark_bypath(char *path, enum strip_type strip, uint32_t cookie)
|
db_watch_mark_bypath(const char *path, enum strip_type strip, uint32_t cookie)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path = '%q';"
|
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path = '%q';"
|
||||||
char *query;
|
char *query;
|
||||||
@ -6368,7 +6389,7 @@ db_watch_mark_bypath(char *path, enum strip_type strip, uint32_t cookie)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_mark_bymatch(char *path, enum strip_type strip, uint32_t cookie)
|
db_watch_mark_bymatch(const char *path, enum strip_type strip, uint32_t cookie)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path LIKE '%q/%%';"
|
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path LIKE '%q/%%';"
|
||||||
char *query;
|
char *query;
|
||||||
@ -6386,7 +6407,7 @@ db_watch_mark_bymatch(char *path, enum strip_type strip, uint32_t cookie)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_move_bycookie(uint32_t cookie, char *path)
|
db_watch_move_bycookie(uint32_t cookie, const char *path)
|
||||||
{
|
{
|
||||||
#define Q_TMPL "UPDATE inotify SET path = '%q' || path, cookie = 0 WHERE cookie = %" PRIi64 ";"
|
#define Q_TMPL "UPDATE inotify SET path = '%q' || path, cookie = 0 WHERE cookie = %" PRIi64 ";"
|
||||||
char *query;
|
char *query;
|
||||||
@ -6611,8 +6632,6 @@ db_pragma_get_cache_size()
|
|||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
||||||
|
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6620,13 +6639,11 @@ db_pragma_get_cache_size()
|
|||||||
if (ret == SQLITE_DONE)
|
if (ret == SQLITE_DONE)
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (ret != SQLITE_ROW)
|
else if (ret != SQLITE_ROW)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
||||||
sqlite3_free(query);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6717,8 +6734,6 @@ db_pragma_get_synchronous()
|
|||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
||||||
|
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6726,13 +6741,11 @@ db_pragma_get_synchronous()
|
|||||||
if (ret == SQLITE_DONE)
|
if (ret == SQLITE_DONE)
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (ret != SQLITE_ROW)
|
else if (ret != SQLITE_ROW)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
||||||
sqlite3_free(query);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6781,8 +6794,6 @@ db_pragma_get_mmap_size()
|
|||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
|
||||||
|
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6790,13 +6801,11 @@ db_pragma_get_mmap_size()
|
|||||||
if (ret == SQLITE_DONE)
|
if (ret == SQLITE_DONE)
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
DPRINTF(E_DBG, L_DB, "End of query results\n");
|
||||||
sqlite3_free(query);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (ret != SQLITE_ROW)
|
else if (ret != SQLITE_ROW)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
|
||||||
sqlite3_free(query);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/db.h
17
src/db.h
@ -573,6 +573,9 @@ free_pli(struct playlist_info *pli, int content_only);
|
|||||||
void
|
void
|
||||||
free_di(struct directory_info *di, int content_only);
|
free_di(struct directory_info *di, int content_only);
|
||||||
|
|
||||||
|
void
|
||||||
|
free_wi(struct watch_info *wi, int content_only);
|
||||||
|
|
||||||
void
|
void
|
||||||
free_query_params(struct query_params *qp, int content_only);
|
free_query_params(struct query_params *qp, int content_only);
|
||||||
|
|
||||||
@ -960,28 +963,28 @@ int
|
|||||||
db_watch_delete_bywd(uint32_t wd);
|
db_watch_delete_bywd(uint32_t wd);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_delete_bypath(char *path);
|
db_watch_delete_bypath(const char *path);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_delete_bymatch(char *path);
|
db_watch_delete_bymatch(const char *path);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_delete_bycookie(uint32_t cookie);
|
db_watch_delete_bycookie(uint32_t cookie);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_get_bywd(struct watch_info *wi);
|
db_watch_get_bywd(struct watch_info *wi, int wd);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_get_bypath(struct watch_info *wi);
|
db_watch_get_bypath(struct watch_info *wi, const char *path);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_mark_bypath(char *path, enum strip_type strip, uint32_t cookie);
|
db_watch_mark_bypath(const char *path, enum strip_type strip, uint32_t cookie);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_mark_bymatch(char *path, enum strip_type strip, uint32_t cookie);
|
db_watch_mark_bymatch(const char *path, enum strip_type strip, uint32_t cookie);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_watch_move_bycookie(uint32_t cookie, char *path);
|
db_watch_move_bycookie(uint32_t cookie, const char *path);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_watch_cookie_known(uint32_t cookie);
|
db_watch_cookie_known(uint32_t cookie);
|
||||||
|
@ -128,7 +128,7 @@ rng_rand_range(struct rng_ctx *ctx, int32_t min, int32_t max)
|
|||||||
* Durstenfeld in-place shuffling variant
|
* Durstenfeld in-place shuffling variant
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
shuffle_int(struct rng_ctx *ctx, int *values, int len)
|
rng_shuffle_int(struct rng_ctx *ctx, int *values, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int32_t j;
|
int32_t j;
|
||||||
|
@ -19,7 +19,7 @@ int32_t
|
|||||||
rng_rand_range(struct rng_ctx *ctx, int32_t min, int32_t max);
|
rng_rand_range(struct rng_ctx *ctx, int32_t min, int32_t max);
|
||||||
|
|
||||||
void
|
void
|
||||||
shuffle_int(struct rng_ctx *ctx, int *values, int len);
|
rng_shuffle_int(struct rng_ctx *ctx, int *values, int len);
|
||||||
|
|
||||||
#endif /* !__RNG_H__ */
|
#endif /* !__RNG_H__ */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user