Skip to content

Commit 37d94d3

Browse files
committed
Fix -Woverflow warning for POSIX_RLIMIT_INFINITY on 32-bit
With a 64-bit rlim_t, RLIM_INFINITY does not fit into a 32-bit zend_long and the implicit conversion warns, which breaks --enable-werror builds. Register -1 in that case, which posix_setrlimit() maps back to RLIM_INFINITY. This is the value the truncation produced already, so the constant does not change on any platform. Also add a test, as POSIX_RLIMIT_INFINITY was not covered by any test.
1 parent 5ccc56b commit 37d94d3

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎ext/posix/posix.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#define POSIX_PID_MAX INT_MAX
5252
#endif
5353

54+
/* RLIM_INFINITY does not fit into a 32-bit zend_long if rlim_t is 64-bit.
55+
* posix_setrlimit() maps -1 to RLIM_INFINITY, so use that in this case. */
56+
#define PHP_POSIX_RLIM_INFINITY (RLIM_INFINITY > ZEND_LONG_MAX ? -1 : (zend_long) RLIM_INFINITY)
57+
5458
#include "posix_arginfo.h"
5559

5660
ZEND_DECLARE_MODULE_GLOBALS(posix)

‎ext/posix/posix.stub.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
#ifdef HAVE_SETRLIMIT
188188
/**
189189
* @var int
190-
* @cvalue RLIM_INFINITY
190+
* @cvalue PHP_POSIX_RLIM_INFINITY
191191
*/
192192
const POSIX_RLIMIT_INFINITY = UNKNOWN;
193193
#endif

‎ext/posix/posix_arginfo.h‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
posix_setrlimit() with POSIX_RLIMIT_INFINITY
3+
--EXTENSIONS--
4+
posix
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists('posix_setrlimit')) die('skip posix_setrlimit() not found');
8+
if (posix_getrlimit(POSIX_RLIMIT_CORE)[1] !== 'unlimited') die('skip hard limit of POSIX_RLIMIT_CORE is not unlimited');
9+
?>
10+
--FILE--
11+
<?php
12+
13+
var_dump(posix_setrlimit(POSIX_RLIMIT_CORE, 1024, POSIX_RLIMIT_INFINITY));
14+
var_dump(posix_getrlimit(POSIX_RLIMIT_CORE));
15+
16+
var_dump(posix_setrlimit(POSIX_RLIMIT_CORE, POSIX_RLIMIT_INFINITY, POSIX_RLIMIT_INFINITY));
17+
var_dump(posix_getrlimit(POSIX_RLIMIT_CORE));
18+
19+
?>
20+
--EXPECT--
21+
bool(true)
22+
array(2) {
23+
[0]=>
24+
int(1024)
25+
[1]=>
26+
string(9) "unlimited"
27+
}
28+
bool(true)
29+
array(2) {
30+
[0]=>
31+
string(9) "unlimited"
32+
[1]=>
33+
string(9) "unlimited"
34+
}

0 commit comments

Comments
 (0)