Skip to content

Commit 15205a2

Browse files
committed
Prevent unnecessary string duplication in assert()
1 parent 7d93ef0 commit 15205a2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ext/standard/assert.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ ZEND_DECLARE_MODULE_GLOBALS(assert)
3434

3535
#define ASSERTG(v) ZEND_MODULE_GLOBALS_ACCESSOR(assert, v)
3636

37-
#define SAFE_STRING(s) ((s)?(s):"")
38-
3937
PHPAPI zend_class_entry *assertion_error_ce;
4038

4139
static PHP_INI_MH(OnChangeCallback) /* {{{ */
@@ -151,9 +149,12 @@ PHP_FUNCTION(assert)
151149
zval args[4];
152150
zval retval;
153151
uint32_t lineno = zend_get_executed_lineno();
154-
const char *filename = zend_get_executed_filename();
152+
const zend_string *filename = zend_get_executed_filename_ex();
153+
if (UNEXPECTED(!filename)) {
154+
filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
155+
}
155156

156-
ZVAL_STRING(&args[0], SAFE_STRING(filename));
157+
ZVAL_STR(&args[0], filename);
157158
ZVAL_LONG(&args[1], lineno);
158159
ZVAL_NULL(&args[2]);
159160

0 commit comments

Comments
 (0)