|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74039 is_infinite(-INF) returns false
Submitted: 2017-02-03 06:26 UTC Modified: 2017-03-17 19:12 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: bugs dot php dot net at chsc dot dk Assigned: nikic (profile)
Status: Closed Package: Math related
PHP Version: 7.0.15 OS: Alpine Linux
Private report: No CVE-ID: None
 [2017-02-03 06:26 UTC] bugs dot php dot net at chsc dot dk
is_infinite() is broken in the PHP binary included in Alpine Linux. It returns TRUE for is_infinite(INF), but FALSE for is_infinite(-INF).

Test script:

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-03 14:56 UTC] g dot sokol99 at g-sokol dot info
On Arch linux PHP 7.1.1 Everything is ok.
 [2017-02-03 15:15 UTC] wilkowski dot kontakt at gmail dot com
On php 5.4.39-0+deb7u2 

var_dump(is_infinite(-INF)); // true
 [2017-02-05 01:51 UTC]
See also: bug #73954
 [2017-02-05 17:15 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-03-17 16:32 UTC] georgi at unixsol dot org
The fix in breaks the build for me for PHP 7.1.3 and PHP 7.0.17 branches:

The build fails with:

ext/filter/.libs/logical_filters.o: In function `php_filter_float':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/filter/logical_filters.c:411: undefined reference to `isfinite'
ext/intl/collator/.libs/collator_is_numeric.o: In function `collator_is_numeric':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/intl/collator/collator_is_numeric.c:255: undefined reference to `isfinite'
ext/standard/.libs/math.o: In function `zif_is_finite':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:589: undefined reference to `isfinite'
ext/standard/.libs/math.o: In function `_php_math_round':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:133: undefined reference to `isfinite'
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:201: undefined reference to `isfinite'
ext/standard/.libs/var.o:/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/var.c:473: more undefined references to `isfinite' follow

After reverting 714d825b62e719447686da6efe3b4063c2f25749, I can build both 7.0 and 7.1 as before.

I can provide any logs necessary to track the problem. The build machine is CentOS 5.5 with glibc-devel-2.5-58.el5_6.3.
 [2017-03-17 16:50 UTC]

#include <math.h>
#ifndef isfinite
# error Not defined
void main() {}

compile for you? This seems pretty weird, because glibc should have isfinite().
 [2017-03-17 19:12 UTC]
CentOS issue also reported in bug #74265.
 [2017-03-20 12:48 UTC] georgi at unixsol dot org
The C example code does not compile on CentOS 5:

georgi@cent5:~$ cat > z.c
#include <math.h>
#ifndef isfinite
# error Not defined
void main() {}
georgi@cent5:~$ gcc z.c
z.c:3:3: error: #error Not defined
z.c: In function ‘main’:
z.c:5: warning: return type of ‘main’ is not ‘int’

georgi@cent5:~$ rpm -qa | grep glibc | sort | uniq
 [2017-03-23 09:05 UTC] bug at example dot com
$ man isfinite 

says that isfinite() is a C99 feature. In order to see what's going on compiler diagnostics helps (please note that the return type of main is int according to all known standards):

#include <stdio.h>
#include <math.h>

int main()
   double d = 0;
   printf ("%d\n", isfinite (d));
   return 0;

   $ gcc -Wall -Werror main.c
   cc1: warnings being treated as errors
   main.c: In function 'main':
   main.c:7: error: implicit declaration of function 'isfinite'

The default mode of GCC is C99 since GCC 5, before it was C89. For those older compilers you have to explitly switch C99-mode on:

   $ gcc -Wall -Werror -std=c99 main.c

The reason why there is an linker error is that for the implicitly declared isfinite() the symbol is the object file and the symbol used in the libc is not "isfinite" but here on my machine "__finite":

   $ nm main.o
                    U __finite
   0000000000000000 T main
                    U printf
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 03:01:28 2024 UTC