From 58502b38d3eaf5649c9e09b6af6ea84d726dccd1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 17 Oct 2013 21:53:19 +0200 Subject: *: use std::numeric_limits --- src/QueueCommands.cxx | 7 ++++--- src/Timer.cxx | 6 ++++-- src/protocol/ArgParser.cxx | 23 ++++++++++------------- src/tag/Aiff.cxx | 4 ++-- src/tag/Riff.cxx | 5 ++--- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/QueueCommands.cxx b/src/QueueCommands.cxx index 01b60e773..7d461a4ab 100644 --- a/src/QueueCommands.cxx +++ b/src/QueueCommands.cxx @@ -35,7 +35,7 @@ #include "util/Error.hxx" #include "fs/Path.hxx" -#include +#include #include @@ -212,7 +212,7 @@ handle_plchangesposid(Client *client, gcc_unused int argc, char *argv[]) enum command_return handle_playlistinfo(Client *client, int argc, char *argv[]) { - unsigned start = 0, end = G_MAXUINT; + unsigned start = 0, end = std::numeric_limits::max(); bool ret; if (argc == 2 && !check_range(client, &start, &end, argv[1])) @@ -239,7 +239,8 @@ handle_playlistid(Client *client, int argc, char *argv[]) return print_playlist_result(client, PLAYLIST_RESULT_NO_SUCH_SONG); } else { - playlist_print_info(client, &client->playlist, 0, G_MAXUINT); + playlist_print_info(client, &client->playlist, + 0, std::numeric_limits::max()); } return COMMAND_RETURN_OK; diff --git a/src/Timer.cxx b/src/Timer.cxx index e32ebe04b..8a1718fbf 100644 --- a/src/Timer.cxx +++ b/src/Timer.cxx @@ -24,6 +24,8 @@ #include +#include + #include #include #include @@ -62,8 +64,8 @@ unsigned Timer::GetDelay() const if (delay < 0) return 0; - if (delay > G_MAXINT) - delay = G_MAXINT; + if (delay > std::numeric_limits::max()) + delay = std::numeric_limits::max(); return delay; } diff --git a/src/protocol/ArgParser.cxx b/src/protocol/ArgParser.cxx index 6bd53a358..e96aaf1c8 100644 --- a/src/protocol/ArgParser.cxx +++ b/src/protocol/ArgParser.cxx @@ -21,7 +21,8 @@ #include "ArgParser.hxx" #include "Result.hxx" -#include +#include + #include bool @@ -51,13 +52,12 @@ check_int(Client *client, int *value_r, const char *s) return false; } -#if G_MAXLONG > G_MAXINT - if (value < G_MININT || value > G_MAXINT) { + if (value < std::numeric_limits::min() || + value > std::numeric_limits::max()) { command_error(client, ACK_ERROR_ARG, "Number too large: %s", s); return false; } -#endif *value_r = (int)value; return true; @@ -81,7 +81,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, /* compatibility with older MPD versions: specifying "-1" makes MPD display the whole list */ *value_r1 = 0; - *value_r2 = G_MAXUINT; + *value_r2 = std::numeric_limits::max(); return true; } @@ -91,13 +91,11 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, return false; } -#if G_MAXLONG > G_MAXUINT - if (value > G_MAXUINT) { + if (unsigned(value) > std::numeric_limits::max()) { command_error(client, ACK_ERROR_ARG, "Number too large: %s", s); return false; } -#endif *value_r1 = (unsigned)value; @@ -110,7 +108,7 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, } if (test == test2) - value = G_MAXUINT; + value = std::numeric_limits::max(); if (value < 0) { command_error(client, ACK_ERROR_ARG, @@ -118,13 +116,12 @@ check_range(Client *client, unsigned *value_r1, unsigned *value_r2, return false; } -#if G_MAXLONG > G_MAXUINT - if (value > G_MAXUINT) { + if (unsigned(value) > std::numeric_limits::max()) { command_error(client, ACK_ERROR_ARG, "Number too large: %s", s); return false; } -#endif + *value_r2 = (unsigned)value; } else { *value_r2 = (unsigned)value + 1; @@ -146,7 +143,7 @@ check_unsigned(Client *client, unsigned *value_r, const char *s) return false; } - if (value > G_MAXUINT) { + if (value > std::numeric_limits::max()) { command_error(client, ACK_ERROR_ARG, "Number too large: %s", s); return false; diff --git a/src/tag/Aiff.cxx b/src/tag/Aiff.cxx index 4135565f7..73e46e49f 100644 --- a/src/tag/Aiff.cxx +++ b/src/tag/Aiff.cxx @@ -23,7 +23,7 @@ #include "system/ByteOrder.hxx" #include "Log.hxx" -#include +#include #include #include @@ -81,7 +81,7 @@ aiff_seek_id3(FILE *file) return 0; size = FromBE32(chunk.size); - if (size > G_MAXINT32) + if (size > unsigned(std::numeric_limits::max())) /* too dangerous, bail out: possible integer underflow when casting to off_t */ return 0; diff --git a/src/tag/Riff.cxx b/src/tag/Riff.cxx index 3728d281c..ad64afc39 100644 --- a/src/tag/Riff.cxx +++ b/src/tag/Riff.cxx @@ -23,12 +23,11 @@ #include "system/ByteOrder.hxx" #include "Log.hxx" -#include +#include #include #include #include -#include #include static constexpr Domain riff_domain("riff"); @@ -79,7 +78,7 @@ riff_seek_id3(FILE *file) return 0; size = FromLE32(chunk.size); - if (size > G_MAXINT32) + if (size > size_t(std::numeric_limits::max())) /* too dangerous, bail out: possible integer underflow when casting to off_t */ return 0; -- cgit v1.2.3