summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schmidt <cs@blackwoodseven.com>2017-02-02 18:52:27 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-02-08 00:53:18 +0100
commit714d825b62e719447686da6efe3b4063c2f25749 (patch)
treeb1984176e18d1eff378f7bf226b4ccb9bf4e34cb
parent044dd30440eb46378288c02d15573f21f17ec927 (diff)
downloadphp-git-714d825b62e719447686da6efe3b4063c2f25749.tar.gz
Fix detection of isnan and isinf
The isnan() and isinf() are C99 macros not functions. Also fix is_infinite(-INF) in case isinf is not defined.
-rw-r--r--NEWS1
-rw-r--r--Zend/Zend.m42
-rw-r--r--Zend/configure.in14
-rw-r--r--configure.in14
-rw-r--r--ext/standard/config.m415
-rw-r--r--ext/standard/tests/math/bug74039.phpt28
6 files changed, 52 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index adc80db1d3..4346259774 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP NEWS
. Fixed bug #73998 (array_key_exists fails on arrays created by
get_object_vars). (mhagstrand)
. Fixed bug #73954 (NAN check fails on Alpine Linux with musl). (Andrea)
+ . Fixed bug #74039 (is_infinite(-INF) returns false). (Christian Schmidt)
- GD:
. Fixed bug #74031 (ReflectionFunction for imagepng is missing last two
diff --git a/Zend/Zend.m4 b/Zend/Zend.m4
index bdeac672b4..fd2b85d2ac 100644
--- a/Zend/Zend.m4
+++ b/Zend/Zend.m4
@@ -100,7 +100,7 @@ AC_FUNC_ALLOCA
AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass sigsetjmp)
AC_ZEND_BROKEN_SPRINTF
-AC_CHECK_FUNCS(finite isfinite isinf isnan)
+AC_CHECK_DECLS([isfinite, isnan, isinf], [], [], [[#include <math.h>]])
ZEND_FP_EXCEPT
diff --git a/Zend/configure.in b/Zend/configure.in
index 3c7915156c..ec339eaef5 100644
--- a/Zend/configure.in
+++ b/Zend/configure.in
@@ -64,13 +64,13 @@ int zend_sprintf(char *buffer, const char *format, ...);
/* To enable the is_nan, is_infinite and is_finite PHP functions */
#ifdef NETWARE
- #define HAVE_ISNAN 1
- #define HAVE_ISINF 1
- #define HAVE_ISFINITE 1
+ #define HAVE_DECL_ISNAN 1
+ #define HAVE_DECL_ISINF 1
+ #define HAVE_DECL_ISFINITE 1
#endif
#ifndef zend_isnan
-#ifdef HAVE_ISNAN
+#ifdef HAVE_DECL_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
@@ -79,18 +79,18 @@ int zend_sprintf(char *buffer, const char *format, ...);
#endif
#endif
-#ifdef HAVE_ISINF
+#ifdef HAVE_DECL_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
-#define zend_isinf(a) (((a)==INFINITY)?1:0)
+#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
#define zend_isinf(a) 0
#endif
-#if defined(HAVE_ISFINITE) || defined(isfinite)
+#if defined(HAVE_DECL_ISFINITE)
#define zend_finite(a) isfinite(a)
#elif defined(HAVE_FINITE)
#define zend_finite(a) finite(a)
diff --git a/configure.in b/configure.in
index b5a3919e5f..b90f53546f 100644
--- a/configure.in
+++ b/configure.in
@@ -69,13 +69,13 @@ int zend_sprintf(char *buffer, const char *format, ...);
/* To enable the is_nan, is_infinite and is_finite PHP functions */
#ifdef NETWARE
- #define HAVE_ISNAN 1
- #define HAVE_ISINF 1
- #define HAVE_ISFINITE 1
+ #define HAVE_DECL_ISNAN 1
+ #define HAVE_DECL_ISINF 1
+ #define HAVE_DECL_ISFINITE 1
#endif
#ifndef zend_isnan
-#ifdef HAVE_ISNAN
+#ifdef HAVE_DECL_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
@@ -84,18 +84,18 @@ int zend_sprintf(char *buffer, const char *format, ...);
#endif
#endif
-#ifdef HAVE_ISINF
+#ifdef HAVE_DECL_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
-#define zend_isinf(a) (((a)==INFINITY)?1:0)
+#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
#define zend_isinf(a) 0
#endif
-#if defined(HAVE_ISFINITE) || defined(isfinite)
+#if defined(HAVE_DECL_ISFINITE)
#define zend_finite(a) isfinite(a)
#elif defined(HAVE_FINITE)
#define zend_finite(a) finite(a)
diff --git a/ext/standard/config.m4 b/ext/standard/config.m4
index ec90af9227..8360cc1552 100644
--- a/ext/standard/config.m4
+++ b/ext/standard/config.m4
@@ -349,7 +349,8 @@ dnl Check for available functions
dnl
dnl log2 could be used to improve the log function, however it requires C99. The check for log2 should be turned on,
dnl as soon as we support C99.
-AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy)
+AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass mempcpy strpncpy)
+AC_CHECK_DECLS([isnan, isinf], [], [], [[#include <math.h>]])
AC_FUNC_FNMATCH
dnl
@@ -420,7 +421,7 @@ AC_TRY_RUN([
#include <math.h>
#include <stdlib.h>
-#ifdef HAVE_ISNAN
+#ifdef HAVE_DECL_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
@@ -451,11 +452,11 @@ AC_TRY_RUN([
#include <math.h>
#include <stdlib.h>
-#ifdef HAVE_ISINF
+#ifdef HAVE_DECL_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
-#define zend_isinf(a) (((a)==INFINITY)?1:0)
+#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
@@ -485,11 +486,11 @@ AC_TRY_RUN([
#include <math.h>
#include <stdlib.h>
-#ifdef HAVE_ISINF
+#ifdef HAVE_DECL_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
-#define zend_isinf(a) (((a)==INFINITY)?1:0)
+#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
@@ -520,7 +521,7 @@ AC_TRY_RUN([
#include <math.h>
#include <stdlib.h>
-#ifdef HAVE_ISNAN
+#ifdef HAVE_DECL_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
diff --git a/ext/standard/tests/math/bug74039.phpt b/ext/standard/tests/math/bug74039.phpt
new file mode 100644
index 0000000000..dd0e1fa260
--- /dev/null
+++ b/ext/standard/tests/math/bug74039.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #74039: is_infinite(-INF) returns false
+--FILE--
+<?php
+
+var_dump(is_finite(INF));
+var_dump(is_infinite(INF));
+var_dump(is_nan(INF));
+
+var_dump(is_finite(-INF));
+var_dump(is_infinite(-INF));
+var_dump(is_nan(-INF));
+
+var_dump(is_finite(NAN));
+var_dump(is_infinite(NAN));
+var_dump(is_nan(NAN));
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+bool(true)