commit 51b78be2358d8318f0e94b1c79bbee0dd6d6cf7b Author: epriestley 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..ea737db 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -165,6 +165,7 @@ check_digits: if (base == 10) { if (digits >= MAX_LENGTH_OF_LONG) { + zend_error(E_WARNING, "String to integer conversion overflowed size of integer"); dp_or_e = -1; goto process_double; } @@ -535,7 +536,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 +547,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 +556,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 +567,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 +611,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 +626,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 +635,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 +650,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 +849,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 +868,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; }