[EMAIL PROTECTED] wrote:
Author: elemings
Date: Thu May 22 13:54:39 2008
New Revision: 659253
URL: http://svn.apache.org/viewvc?rev=659253&view=rev
Log:
2008-05-22 Eric Lemings <[EMAIL PROTECTED]>
STDCXX-550
[...]
* util/cmdopt.cpp: Explicitly cast return value of sysconf()
function to `float' type used by `TICKS_PER_SEC' global.
(eval_options): Cast return value of strtol() function to
`unsigned' type. Second parameter of get_long_val() function
expects `unsigned' type (go figure). Cast return value of
sizeof operator. exit() function expects `int' status code.
Parameter type of rw_sleep() function is `int'.
[...]
Modified: stdcxx/branches/4.2.x/util/cmdopt.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/util/cmdopt.cpp?rev=659253&r1=659252&r2=659253&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/util/cmdopt.cpp (original)
+++ stdcxx/branches/4.2.x/util/cmdopt.cpp Thu May 22 13:54:39 2008
@@ -59,7 +59,7 @@
const char suffix_sep = '.';
const size_t exe_suffix_len = 0;
#if defined (_SC_CLK_TCK)
-const float TICKS_PER_SEC = sysconf (_SC_CLK_TCK);
+const float TICKS_PER_SEC = float (sysconf (_SC_CLK_TCK));
(As an aside, I wonder why this is defined here when the only
place it's used is display.cpp. We should move it there.)
#elif defined (CLK_TCK)
const float TICKS_PER_SEC = CLK_TCK;
#elif defined (CLOCKS_PER_SEC)
@@ -521,7 +521,7 @@
bad_value (optname, optarg);
errno = 0;
- defaults->timeout = strtol (optarg, &end, 10);
+ defaults->timeout = unsigned (strtol (optarg, &end, 10));
I suggest using strtoul() here instead.
if (*end || errno)
bad_value (optname, optarg);
}
@@ -573,7 +573,7 @@
&& !memcmp (opt_exit, argv [i], sizeof opt_exit - 1)) {
/* exit immediately with the specified status */
optname = opt_exit;
- optarg = get_long_val (argv, &i, sizeof opt_exit - 1);
+ optarg = get_long_val (argv, &i, unsigned (sizeof opt_exit -
1));
I suggest changing the get_long_val() signature to take size_t
as the last argument (it will also help reduce the line length
under 80 characters ;-)
if (optarg && *optarg) {
if (!isdigit (*optarg))
bad_value (optname, optarg);
@@ -581,7 +581,7 @@
errno = 0;
const long code = strtol (optarg, &end, 10);
if ('\0' == *end && !errno)
- exit (code);
+ exit (int (code));
Seems this code (not necessarily the change) could do with some
error checking and reporting...
}
}
else if ( sizeof opt_help - 1 == arglen
@@ -595,7 +595,7 @@
&& !memcmp (opt_sleep, argv [i], sizeof opt_sleep - 1)) {
/* sleep for the specified number of seconds */
optname = opt_sleep;
- optarg = get_long_val (argv, &i, sizeof opt_sleep - 1);
+ optarg = get_long_val (argv, &i, unsigned (sizeof opt_sleep -
1));
if (optarg && *optarg) {
if (!isdigit (*optarg))
bad_value (optname, optarg);
@@ -603,7 +603,7 @@
errno = 0;
const long nsec = strtol (optarg, &end, 10);
if ('\0' == *end && 0 <= nsec && !errno) {
- rw_sleep (nsec);
+ rw_sleep (int (nsec));
Same here (e.g., passing in a very large number on the command
line as a result of a scripting error).
Martin