Commit 58502b38 authored by Max Kellermann's avatar Max Kellermann

*: use std::numeric_limits

parent d44880df
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include <glib.h> #include <limits>
#include <string.h> #include <string.h>
...@@ -212,7 +212,7 @@ handle_plchangesposid(Client *client, gcc_unused int argc, char *argv[]) ...@@ -212,7 +212,7 @@ handle_plchangesposid(Client *client, gcc_unused int argc, char *argv[])
enum command_return enum command_return
handle_playlistinfo(Client *client, int argc, char *argv[]) handle_playlistinfo(Client *client, int argc, char *argv[])
{ {
unsigned start = 0, end = G_MAXUINT; unsigned start = 0, end = std::numeric_limits<unsigned>::max();
bool ret; bool ret;
if (argc == 2 && !check_range(client, &start, &end, argv[1])) if (argc == 2 && !check_range(client, &start, &end, argv[1]))
...@@ -239,7 +239,8 @@ handle_playlistid(Client *client, int argc, char *argv[]) ...@@ -239,7 +239,8 @@ handle_playlistid(Client *client, int argc, char *argv[])
return print_playlist_result(client, return print_playlist_result(client,
PLAYLIST_RESULT_NO_SUCH_SONG); PLAYLIST_RESULT_NO_SUCH_SONG);
} else { } else {
playlist_print_info(client, &client->playlist, 0, G_MAXUINT); playlist_print_info(client, &client->playlist,
0, std::numeric_limits<unsigned>::max());
} }
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <glib.h> #include <glib.h>
#include <limits>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
...@@ -62,8 +64,8 @@ unsigned Timer::GetDelay() const ...@@ -62,8 +64,8 @@ unsigned Timer::GetDelay() const
if (delay < 0) if (delay < 0)
return 0; return 0;
if (delay > G_MAXINT) if (delay > std::numeric_limits<int>::max())
delay = G_MAXINT; delay = std::numeric_limits<int>::max();
return delay; return delay;
} }
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#include "ArgParser.hxx" #include "ArgParser.hxx"
#include "Result.hxx" #include "Result.hxx"
#include <glib.h> #include <limits>
#include <stdlib.h> #include <stdlib.h>
bool bool
...@@ -51,13 +52,12 @@ check_int(Client *client, int *value_r, const char *s) ...@@ -51,13 +52,12 @@ check_int(Client *client, int *value_r, const char *s)
return false; return false;
} }
#if G_MAXLONG > G_MAXINT if (value < std::numeric_limits<int>::min() ||
if (value < G_MININT || value > G_MAXINT) { value > std::numeric_limits<int>::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
*value_r = (int)value; *value_r = (int)value;
return true; return true;
...@@ -81,7 +81,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, ...@@ -81,7 +81,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2,
/* compatibility with older MPD versions: specifying /* compatibility with older MPD versions: specifying
"-1" makes MPD display the whole list */ "-1" makes MPD display the whole list */
*value_r1 = 0; *value_r1 = 0;
*value_r2 = G_MAXUINT; *value_r2 = std::numeric_limits<unsigned>::max();
return true; return true;
} }
...@@ -91,13 +91,11 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, ...@@ -91,13 +91,11 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2,
return false; return false;
} }
#if G_MAXLONG > G_MAXUINT if (unsigned(value) > std::numeric_limits<unsigned>::max()) {
if (value > G_MAXUINT) {
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
*value_r1 = (unsigned)value; *value_r1 = (unsigned)value;
...@@ -110,7 +108,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, ...@@ -110,7 +108,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2,
} }
if (test == test2) if (test == test2)
value = G_MAXUINT; value = std::numeric_limits<unsigned>::max();
if (value < 0) { if (value < 0) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
...@@ -118,13 +116,12 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, ...@@ -118,13 +116,12 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2,
return false; return false;
} }
#if G_MAXLONG > G_MAXUINT if (unsigned(value) > std::numeric_limits<unsigned>::max()) {
if (value > G_MAXUINT) {
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
*value_r2 = (unsigned)value; *value_r2 = (unsigned)value;
} else { } else {
*value_r2 = (unsigned)value + 1; *value_r2 = (unsigned)value + 1;
...@@ -146,7 +143,7 @@ check_unsigned(Client *client, unsigned *value_r, const char *s) ...@@ -146,7 +143,7 @@ check_unsigned(Client *client, unsigned *value_r, const char *s)
return false; return false;
} }
if (value > G_MAXUINT) { if (value > std::numeric_limits<unsigned>::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;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "system/ByteOrder.hxx" #include "system/ByteOrder.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <glib.h> #include <limits>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -81,7 +81,7 @@ aiff_seek_id3(FILE *file) ...@@ -81,7 +81,7 @@ aiff_seek_id3(FILE *file)
return 0; return 0;
size = FromBE32(chunk.size); size = FromBE32(chunk.size);
if (size > G_MAXINT32) if (size > unsigned(std::numeric_limits<int>::max()))
/* too dangerous, bail out: possible integer /* too dangerous, bail out: possible integer
underflow when casting to off_t */ underflow when casting to off_t */
return 0; return 0;
......
...@@ -23,12 +23,11 @@ ...@@ -23,12 +23,11 @@
#include "system/ByteOrder.hxx" #include "system/ByteOrder.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <glib.h> #include <limits>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <string.h> #include <string.h>
static constexpr Domain riff_domain("riff"); static constexpr Domain riff_domain("riff");
...@@ -79,7 +78,7 @@ riff_seek_id3(FILE *file) ...@@ -79,7 +78,7 @@ riff_seek_id3(FILE *file)
return 0; return 0;
size = FromLE32(chunk.size); size = FromLE32(chunk.size);
if (size > G_MAXINT32) if (size > size_t(std::numeric_limits<int>::max()))
/* too dangerous, bail out: possible integer /* too dangerous, bail out: possible integer
underflow when casting to off_t */ underflow when casting to off_t */
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment