playlist: pass unsigned integers to playlistInfo()
A song index cannot be negative. Also require the second parameter to be valid.
This commit is contained in:
parent
b7c4b78846
commit
8ebe7bfb25
@ -162,7 +162,7 @@ check_int(struct client *client, int *value_r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool G_GNUC_PRINTF(5, 6)
|
static bool G_GNUC_PRINTF(5, 6)
|
||||||
check_range(struct client *client, int *value_r1, int *value_r2,
|
check_range(struct client *client, unsigned *value_r1, unsigned *value_r2,
|
||||||
const char *s, const char *fmt, ...)
|
const char *s, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char *test, *test2;
|
char *test, *test2;
|
||||||
@ -177,15 +177,21 @@ check_range(struct client *client, int *value_r1, int *value_r2,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LONG_MAX > INT_MAX
|
if (value < 0) {
|
||||||
if (value < INT_MIN || value > INT_MAX) {
|
command_error(client, ACK_ERROR_ARG,
|
||||||
|
"Number is negative: %s", s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LONG_MAX > UINT_MAX
|
||||||
|
if (value > UINT_MAX) {
|
||||||
command_error(client, ACK_ERROR_ARG,
|
command_error(client, ACK_ERROR_ARG,
|
||||||
"Number too large: %s", s);
|
"Number too large: %s", s);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*value_r1 = (int)value;
|
*value_r1 = (unsigned)value;
|
||||||
|
|
||||||
if (*test == ':') {
|
if (*test == ':') {
|
||||||
value = strtol(++test, &test2, 10);
|
value = strtol(++test, &test2, 10);
|
||||||
@ -196,14 +202,23 @@ check_range(struct client *client, int *value_r1, int *value_r2,
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#if LONG_MAX > INT_MAX
|
|
||||||
if (value < INT_MIN || value > INT_MAX) {
|
if (value < 0) {
|
||||||
|
command_error(client, ACK_ERROR_ARG,
|
||||||
|
"Number is negative: %s", s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LONG_MAX > UINT_MAX
|
||||||
|
if (value > UINT_MAX) {
|
||||||
command_error(client, ACK_ERROR_ARG,
|
command_error(client, ACK_ERROR_ARG,
|
||||||
"Number too large: %s", s);
|
"Number too large: %s", s);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*value_r2 = (int)value;
|
*value_r2 = (unsigned)value;
|
||||||
|
} else {
|
||||||
|
*value_r2 = (unsigned)value + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -743,13 +758,14 @@ handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[
|
|||||||
static enum command_return
|
static enum command_return
|
||||||
handle_playlistinfo(struct client *client, int argc, char *argv[])
|
handle_playlistinfo(struct client *client, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int song = -1, max = -1;
|
unsigned start = 0, end = UINT_MAX;
|
||||||
enum playlist_result result;
|
enum playlist_result result;
|
||||||
|
|
||||||
if (argc == 2 && !check_range(client, &song, &max, argv[1], need_range))
|
if (argc == 2 && !check_range(client, &start, &end,
|
||||||
|
argv[1], need_range))
|
||||||
return COMMAND_RETURN_ERROR;
|
return COMMAND_RETURN_ERROR;
|
||||||
|
|
||||||
result = playlistInfo(client, song, max);
|
result = playlistInfo(client, start, end);
|
||||||
return print_playlist_result(client, result);
|
return print_playlist_result(client, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,24 +413,16 @@ int playlistChangesPosId(struct client *client, uint32_t version)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum playlist_result playlistInfo(struct client *client, int song, int max)
|
enum playlist_result
|
||||||
|
playlistInfo(struct client *client, unsigned start, unsigned end)
|
||||||
{
|
{
|
||||||
unsigned begin = 0;
|
if (end > playlist.length)
|
||||||
unsigned end = playlist.length;
|
end = playlist.length;
|
||||||
|
|
||||||
if (song >= 0) {
|
if (start > end)
|
||||||
begin = song;
|
|
||||||
end = song + 1;
|
|
||||||
}
|
|
||||||
if (song >= (int)playlist.length)
|
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
return PLAYLIST_RESULT_BAD_RANGE;
|
||||||
if (max > 0) {
|
|
||||||
end = MIN((unsigned)max, playlist.length);
|
|
||||||
if (end <= begin)
|
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = begin; i < end; i++)
|
for (unsigned i = start; i < end; i++)
|
||||||
printPlaylistSongInfo(client, i);
|
printPlaylistSongInfo(client, i);
|
||||||
|
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
return PLAYLIST_RESULT_SUCCESS;
|
||||||
|
@ -95,7 +95,16 @@ enum playlist_result deleteFromPlaylist(unsigned song);
|
|||||||
|
|
||||||
enum playlist_result deleteFromPlaylistById(unsigned song);
|
enum playlist_result deleteFromPlaylistById(unsigned song);
|
||||||
|
|
||||||
enum playlist_result playlistInfo(struct client *client, int song, int max);
|
/**
|
||||||
|
* Send detailed information about a range of songs in the playlist to
|
||||||
|
* a client.
|
||||||
|
*
|
||||||
|
* @param client the client which has requested information
|
||||||
|
* @param start the index of the first song (including)
|
||||||
|
* @param end the index of the last song (excluding)
|
||||||
|
*/
|
||||||
|
enum playlist_result
|
||||||
|
playlistInfo(struct client *client, unsigned start, unsigned end);
|
||||||
|
|
||||||
enum playlist_result playlistId(struct client *client, int song);
|
enum playlist_result playlistId(struct client *client, int song);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user