]> granicus.if.org Git - php/commitdiff
MFB: Check for negative precision
authorRasmus Lerdorf <rasmus@php.net>
Wed, 2 Apr 2003 23:51:52 +0000 (23:51 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Wed, 2 Apr 2003 23:51:52 +0000 (23:51 +0000)
ext/bcmath/bcmath.c

index 60e2a5ce4b17f1191498dab3efcfe9049b06a0c5..b5b16716b7b61288d9fcfc3e7b73dc739a062bec 100644 (file)
@@ -97,7 +97,7 @@ PHP_RINIT_FUNCTION(bcmath)
        if (cfg_get_long("bcmath.scale", &bc_precision) == FAILURE) {
                bc_precision = 0;
        }
-       
+       if(bc_precision<0) bc_precision=0;
        bc_init_numbers(TSRMLS_C);
        
        return SUCCESS;
@@ -145,7 +145,7 @@ PHP_FUNCTION(bcadd)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -191,7 +191,7 @@ PHP_FUNCTION(bcsub)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -237,7 +237,7 @@ PHP_FUNCTION(bcmul)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -283,7 +283,7 @@ PHP_FUNCTION(bcdiv)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -411,7 +411,7 @@ PHP_FUNCTION(bcpow)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -457,7 +457,7 @@ PHP_FUNCTION(bcsqrt)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -500,7 +500,7 @@ PHP_FUNCTION(bccomp)
                                        WRONG_PARAM_COUNT;
                                }
                                convert_to_long_ex(scale_param);
-                               scale = (int) Z_LVAL_PP(scale_param);
+                               scale = (int) (Z_LVAL_PP(scale_param)<0) ? 0:Z_LVAL_PP(scale_param);
                                break;
                default:
                                WRONG_PARAM_COUNT;
@@ -534,7 +534,8 @@ PHP_FUNCTION(bcscale)
        }
        
        convert_to_long_ex(new_scale);
-       bc_precision = Z_LVAL_PP(new_scale);
+       bc_precision = (Z_LVAL_PP(new_scale)<0) ? 0 : Z_LVAL_PP(new_scale);
+
        RETURN_TRUE;
 }
 /* }}} */