]> granicus.if.org Git - php/commitdiff
Fix detection of isnan and isinf
authorChristian Schmidt <cs@blackwoodseven.com>
Thu, 2 Feb 2017 17:52:27 +0000 (18:52 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 5 Feb 2017 17:09:04 +0000 (18:09 +0100)
The isnan() and isinf() are C99 macros not functions.

Also fix is_infinite(-INF) in case isinf is not defined.

NEWS
Zend/Zend.m4
Zend/configure.in
configure.in
ext/standard/config.m4
ext/standard/tests/math/bug74039.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index adc80db1d3143acb05f5a055d5b671a68a94d609..43462597741ca76ed074b507a8a9e630508be004 100644 (file)
--- 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
index bdeac672b403014b3d6b2adfc93683b0933ee154..6ec9ed02e12e2b749f9f4e8503492deac9f5f849 100644 (file)
@@ -100,7 +100,8 @@ 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_FUNCS(finite)
+AC_CHECK_DECLS([isfinite, isnan, isinf], [], [], [[#include <math.h>]])
 
 ZEND_FP_EXCEPT
 
index 3c7915156cb76c7dc840abe2993b7ab1c48f51ae..5733b30ce06aa2d80ac19b2c17460c96033dc455 100644 (file)
@@ -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_ISINFINITE 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_ISINFINITE) || defined(isfinite)
 #define zend_finite(a) isfinite(a)
 #elif defined(HAVE_FINITE)
 #define zend_finite(a) finite(a)
index b5a3919e5fd54db35151f8e6ff3b4903f73e9f0e..d2f75670515d453abcc8c6f0975ed6a00dba0a6f 100644 (file)
@@ -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_ISINFINITE 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_ISINFINITE) || defined(isfinite)
 #define zend_finite(a) isfinite(a)
 #elif defined(HAVE_FINITE)
 #define zend_finite(a) finite(a)
index ec90af92276b23b78219e87624c6d018e51dfcab..ea5ce0626c3150df7ef8912f7e996fb494a09de3 100644 (file)
@@ -420,7 +420,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 +451,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 +485,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 +520,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 (file)
index 0000000..dd0e1fa
--- /dev/null
@@ -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)