aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-10 17:39:49 +0100
committerMax Kellermann <max@duempel.org>2009-01-10 17:39:49 +0100
commit8ebe7bfb250f2b1048d6e7f6c2477717daaad8e9 (patch)
tree51dfa41888a76bdd992eb729df7740adb84f42fb /src/command.c
parentb7c4b78846cf2eba35517a1a0c435a3a056636f5 (diff)
downloadmpd-8ebe7bfb250f2b1048d6e7f6c2477717daaad8e9.tar.gz
mpd-8ebe7bfb250f2b1048d6e7f6c2477717daaad8e9.tar.xz
mpd-8ebe7bfb250f2b1048d6e7f6c2477717daaad8e9.zip
playlist: pass unsigned integers to playlistInfo()
A song index cannot be negative. Also require the second parameter to be valid.
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/command.c b/src/command.c
index a00607fce..646f76bf5 100644
--- a/src/command.c
+++ b/src/command.c
@@ -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, song, max);
+ result = playlistInfo(client, start, end);
return print_playlist_result(client, result);
}