Ken ICHIKAWA
2013-08-22 08:24:29 UTC
double precision cannot recognize difference between 9223372036854775807
and 9223372036854775808. Therefore, even if phc_interval is
9223372036854775808.0 and INT64_MAX is 9223372036854775807,
phc_interval > INT64_MAX is FALSE. As a result, 9223372036854775808.0
is assigned to time_t variable and that causes overflow of time_t.
long double can recognize the difference. So, we compare phc_interval
and INT64_MAX in long double.
Signed-off-by: Ken ICHIKAWA <***@jp.fujitsu.com>
---
phc2sys.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/phc2sys.c b/phc2sys.c
index 157d0e8..bc497be 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -639,7 +639,8 @@ int main(int argc, char *argv[])
phc_interval = 1.0 / phc_rate;
/* phc_interval will be assigned to a time_t variable. */
/* check if that occurs overflow. */
- if ((sizeof(time_t) == 8 && phc_interval > INT64_MAX) ||
+ if ((sizeof(time_t) == 8 &&
+ phc_interval > (long double)INT64_MAX) ||
(sizeof(time_t) == 4 && phc_interval > INT32_MAX)) {
fprintf(stderr,
"-R: %s is too small\n", optarg);
and 9223372036854775808. Therefore, even if phc_interval is
9223372036854775808.0 and INT64_MAX is 9223372036854775807,
phc_interval > INT64_MAX is FALSE. As a result, 9223372036854775808.0
is assigned to time_t variable and that causes overflow of time_t.
long double can recognize the difference. So, we compare phc_interval
and INT64_MAX in long double.
Signed-off-by: Ken ICHIKAWA <***@jp.fujitsu.com>
---
phc2sys.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/phc2sys.c b/phc2sys.c
index 157d0e8..bc497be 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -639,7 +639,8 @@ int main(int argc, char *argv[])
phc_interval = 1.0 / phc_rate;
/* phc_interval will be assigned to a time_t variable. */
/* check if that occurs overflow. */
- if ((sizeof(time_t) == 8 && phc_interval > INT64_MAX) ||
+ if ((sizeof(time_t) == 8 &&
+ phc_interval > (long double)INT64_MAX) ||
(sizeof(time_t) == 4 && phc_interval > INT32_MAX)) {
fprintf(stderr,
"-R: %s is too small\n", optarg);
--
1.7.1
1.7.1