Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F29188
strict.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
epriestley
Jan 14 2013, 3:01 AM
2013-01-14 03:01:41 (UTC+0)
Size
5 KB
Referenced Files
None
Subscribers
None
strict.diff
View Options
commit e036197dabf3d6b4b8fe7106bdf24cef29b2ffed
Author: epriestley <git@epriestley.com>
Date: Sun Jan 13 19:04:30 2013 -0800
Issue warnings when comparing strings or unlike types.
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index a849ccc..883787f 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -1401,6 +1401,12 @@ static inline void zend_free_obj_get_result(zval *op TSRMLS_DC) /* {{{ */
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
+ return compare_function_ex(result, op1, op2, 0 TSRMLS_CC);
+}
+/* }}} */
+
+ZEND_API int compare_function_ex(zval *result, zval *op1, zval *op2, int strict TSRMLS_DC) /* {{{ */
+{
int ret;
int converted = 0;
zval op1_copy, op2_copy;
@@ -1452,6 +1458,9 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
return SUCCESS;
case TYPE_PAIR(IS_STRING, IS_STRING):
+ if (strict) {
+ zend_error(E_WARNING, "Operator comparison of strings, use strcmp().");
+ }
zendi_smart_strcmp(result, op1, op2);
return SUCCESS;
@@ -1485,6 +1494,9 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
/* break missing intentionally */
default:
+ if (strict && (Z_TYPE_P(op1) != IS_BOOL) && (Z_TYPE_P(op2) != IS_BOOL)) {
+ zend_error(E_WARNING, "Operator comparison of unlike types.");
+ }
if (Z_TYPE_P(op1) == IS_OBJECT) {
if (Z_OBJ_HT_P(op1)->get) {
op_free = Z_OBJ_HT_P(op1)->get(op1 TSRMLS_CC);
@@ -1654,7 +1666,7 @@ ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
+ if (compare_function_ex(result, op1, op2, 1 TSRMLS_CC) == FAILURE) {
return FAILURE;
}
ZVAL_BOOL(result, (Z_LVAL_P(result) < 0));
@@ -1664,7 +1676,7 @@ ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /
ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- if (compare_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
+ if (compare_function_ex(result, op1, op2, 1 TSRMLS_CC) == FAILURE) {
return FAILURE;
}
ZVAL_BOOL(result, (Z_LVAL_P(result) <= 0));
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index ebf959b..1645de8 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -535,7 +535,7 @@ static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *o
__asm__(
"movl (%1), %%eax\n\t"
"addl (%2), %%eax\n\t"
- "jo 0f\n\t"
+ "jo 0f\n\t"
"movl %%eax, (%0)\n\t"
"movb $0x1,0xc(%0)\n\t"
"jmp 1f\n"
@@ -546,7 +546,7 @@ static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *o
"movb $0x2,0xc(%0)\n\t"
"fstpl (%0)\n"
"1:"
- :
+ :
: "r"(result),
"r"(op1),
"r"(op2)
@@ -555,7 +555,7 @@ static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *o
__asm__(
"movq (%1), %%rax\n\t"
"addq (%2), %%rax\n\t"
- "jo 0f\n\t"
+ "jo 0f\n\t"
"movq %%rax, (%0)\n\t"
"movb $0x1,0x14(%0)\n\t"
"jmp 1f\n"
@@ -566,7 +566,7 @@ static zend_always_inline int fast_add_function(zval *result, zval *op1, zval *o
"movb $0x2,0x14(%0)\n\t"
"fstpl (%0)\n"
"1:"
- :
+ :
: "r"(result),
"r"(op1),
"r"(op2)
@@ -610,7 +610,7 @@ static zend_always_inline int fast_sub_function(zval *result, zval *op1, zval *o
__asm__(
"movl (%1), %%eax\n\t"
"subl (%2), %%eax\n\t"
- "jo 0f\n\t"
+ "jo 0f\n\t"
"movl %%eax, (%0)\n\t"
"movb $0x1,0xc(%0)\n\t"
"jmp 1f\n"
@@ -625,7 +625,7 @@ static zend_always_inline int fast_sub_function(zval *result, zval *op1, zval *o
"movb $0x2,0xc(%0)\n\t"
"fstpl (%0)\n"
"1:"
- :
+ :
: "r"(result),
"r"(op1),
"r"(op2)
@@ -634,7 +634,7 @@ static zend_always_inline int fast_sub_function(zval *result, zval *op1, zval *o
__asm__(
"movq (%1), %%rax\n\t"
"subq (%2), %%rax\n\t"
- "jo 0f\n\t"
+ "jo 0f\n\t"
"movq %%rax, (%0)\n\t"
"movb $0x1,0x14(%0)\n\t"
"jmp 1f\n"
@@ -649,7 +649,7 @@ static zend_always_inline int fast_sub_function(zval *result, zval *op1, zval *o
"movb $0x2,0x14(%0)\n\t"
"fstpl (%0)\n"
"1:"
- :
+ :
: "r"(result),
"r"(op1),
"r"(op2)
@@ -848,7 +848,7 @@ static zend_always_inline int fast_is_smaller_function(zval *result, zval *op1,
return Z_DVAL_P(op1) < ((double)Z_LVAL_P(op2));
}
}
- compare_function(result, op1, op2 TSRMLS_CC);
+ compare_function_ex(result, op1, op2, 1 TSRMLS_CC);
return Z_LVAL_P(result) < 0;
}
@@ -867,7 +867,7 @@ static zend_always_inline int fast_is_smaller_or_equal_function(zval *result, zv
return Z_DVAL_P(op1) <= ((double)Z_LVAL_P(op2));
}
}
- compare_function(result, op1, op2 TSRMLS_CC);
+ compare_function_ex(result, op1, op2, 1 TSRMLS_CC);
return Z_LVAL_P(result) <= 0;
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/3x/gq/3y6d7hexochdv5y7
Default Alt Text
strict.diff (5 KB)
Attached To
Mode
P663 strict.diff
Attached
Detach File
Event Timeline
Log In to Comment