[spotify] Coverity fixups

This commit is contained in:
ejurgensen 2022-01-20 20:08:18 +01:00
parent 0fdca0587c
commit cd4386228d
5 changed files with 27 additions and 8 deletions

View File

@ -51,7 +51,7 @@ path_to_media_id_and_type(struct sp_file *file)
struct sp_channel *
channel_get(uint32_t channel_id, struct sp_session *session)
{
if (channel_id > sizeof(session->channels)/sizeof(session->channels)[0])
if (channel_id >= sizeof(session->channels)/sizeof(session->channels)[0])
return NULL;
if (session->channels[channel_id].state == SP_CHANNEL_STATE_UNALLOCATED)
@ -148,6 +148,7 @@ channel_flush(struct sp_channel *channel)
int fd = channel->audio_fd[0];
int flags;
int got;
int ret;
evbuffer_drain(channel->audio_buf, -1);
@ -157,13 +158,18 @@ channel_flush(struct sp_channel *channel)
if (flags == -1)
return -1;
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
if (ret < 0)
return -1;
do
got = read(fd, buf, sizeof(buf));
while (got > 0);
fcntl(fd, F_SETFL, flags);
ret = fcntl(fd, F_SETFL, flags);
if (ret < 0)
return -1;
return 0;
}

View File

@ -207,6 +207,10 @@ commands_base_new(struct event_base *evbase, command_exit_cb exit_cb)
int ret;
cmdbase = calloc(1, sizeof(struct commands_base));
if (!cmdbase)
{
return NULL;
}
#ifdef HAVE_PIPE2
ret = pipe2(cmdbase->command_pipe, O_CLOEXEC);
@ -370,6 +374,9 @@ commands_exec_async(struct commands_base *cmdbase, command_function func, void *
int ret;
cmd = calloc(1, sizeof(struct command));
if (!cmd)
return -1;
cmd->func = func;
cmd->func_bh = NULL;
cmd->arg = arg;

View File

@ -620,7 +620,7 @@ response_aplogin_failed(uint8_t *payload, size_t payload_len, struct sp_session
}
sp_errmsg = "(unknown login error)";
for (int i = 0; i < sizeof(sp_login_errors); i++)
for (int i = 0; i < sizeof(sp_login_errors)/sizeof(sp_login_errors[0]); i++)
{
if (sp_login_errors[i].errorcode != aplogin_failed->error_code)
continue;

View File

@ -48,6 +48,7 @@ events for proceeding are activated directly.
*/
#include <pthread.h>
#include <assert.h>
#include "librespot-c-internal.h"
#include "commands.h"
@ -833,6 +834,8 @@ librespotc_write(int fd, sp_progress_cb progress_cb, void *cb_arg)
cmdargs = calloc(1, sizeof(struct sp_cmdargs));
assert(cmdargs);
cmdargs->fd_read = fd;
cmdargs->progress_cb = progress_cb;
cmdargs->cb_arg = cb_arg;

View File

@ -351,9 +351,10 @@ request_endpoint(const char *uri)
json_object *json_response = NULL;
int ret;
ctx = calloc(1, sizeof(struct http_client_ctx));
ctx->output_headers = calloc(1, sizeof(struct keyval));
ctx->input_body = evbuffer_new();
CHECK_NULL(L_SPOTIFY, ctx = calloc(1, sizeof(struct http_client_ctx)));
CHECK_NULL(L_SPOTIFY, ctx->output_headers = calloc(1, sizeof(struct keyval)));
CHECK_NULL(L_SPOTIFY, ctx->input_body = evbuffer_new());
ctx->url = uri;
snprintf(bearer_token, sizeof(bearer_token), "Bearer %s", spotify_credentials.access_token);
@ -1091,7 +1092,9 @@ spotifywebapi_oauth_uri_get(const char *redirect_uri)
if (param)
{
uri_len = strlen(spotify_auth_uri) + strlen(param) + 3;
uri = calloc(uri_len, sizeof(char));
CHECK_NULL(L_SPOTIFY, uri = calloc(uri_len, sizeof(char)));
snprintf(uri, uri_len, "%s/?%s", spotify_auth_uri, param);
free(param);