Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8ebe7bfb
Commit
8ebe7bfb
authored
Jan 10, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playlist: pass unsigned integers to playlistInfo()
A song index cannot be negative. Also require the second parameter to be valid.
parent
b7c4b788
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
25 deletions
+42
-25
command.c
src/command.c
+26
-10
playlist.c
src/playlist.c
+6
-14
playlist.h
src/playlist.h
+10
-1
No files found.
src/command.c
View file @
8ebe7bfb
...
...
@@ -162,7 +162,7 @@ check_int(struct client *client, int *value_r,
}
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
,
...)
{
char
*
test
,
*
test2
;
...
...
@@ -177,15 +177,21 @@ check_range(struct client *client, int *value_r1, int *value_r2,
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
,
"Number too large: %s"
,
s
);
return
false
;
}
#endif
*
value_r1
=
(
int
)
value
;
*
value_r1
=
(
unsigned
)
value
;
if
(
*
test
==
':'
)
{
value
=
strtol
(
++
test
,
&
test2
,
10
);
...
...
@@ -196,14 +202,23 @@ check_range(struct client *client, int *value_r1, int *value_r2,
va_end
(
args
);
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
,
"Number too large: %s"
,
s
);
return
false
;
}
#endif
*
value_r2
=
(
int
)
value
;
*
value_r2
=
(
unsigned
)
value
;
}
else
{
*
value_r2
=
(
unsigned
)
value
+
1
;
}
return
true
;
...
...
@@ -743,13 +758,14 @@ handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[
static
enum
command_return
handle_playlistinfo
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
int
song
=
-
1
,
max
=
-
1
;
unsigned
start
=
0
,
end
=
UINT_MAX
;
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
;
result
=
playlistInfo
(
client
,
s
ong
,
max
);
result
=
playlistInfo
(
client
,
s
tart
,
end
);
return
print_playlist_result
(
client
,
result
);
}
...
...
src/playlist.c
View file @
8ebe7bfb
...
...
@@ -413,24 +413,16 @@ int playlistChangesPosId(struct client *client, uint32_t version)
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
;
unsigned
end
=
playlist
.
length
;
if
(
end
>
playlist
.
length
)
end
=
playlist
.
length
;
if
(
song
>=
0
)
{
begin
=
song
;
end
=
song
+
1
;
}
if
(
song
>=
(
int
)
playlist
.
length
)
if
(
start
>
end
)
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
);
return
PLAYLIST_RESULT_SUCCESS
;
...
...
src/playlist.h
View file @
8ebe7bfb
...
...
@@ -95,7 +95,16 @@ enum playlist_result deleteFromPlaylist(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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment