summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-02-12 13:15:20 +0000
committerNicholas Clark <nick@ccl4.org>2008-02-12 13:15:20 +0000
commit7918f24d20384771923d344a382e1d16d9552018 (patch)
tree627e24f3c520f70ddfd3fc9779420bd72fd00c55 /numeric.c
parent9f10164a6c9d93684fedbbc188fb9dfe004c22c4 (diff)
downloadperl-7918f24d20384771923d344a382e1d16d9552018.tar.gz
assert() that every NN argument is not NULL. Otherwise we have the
ability to create landmines that will explode under someone in the future when they upgrade their compiler to one with better optimisation. We've already done this at least twice. (Yes, some of the assertions are after code that would already have SEGVd because it already deferences a pointer, but they are put in to make it easier to automate checking that each and every case is covered.) Add a tool, checkARGS_ASSERT.pl, to check that every case is covered. p4raw-id: //depot/perl@33291
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/numeric.c b/numeric.c
index b3355a4c54..761239a1cb 100644
--- a/numeric.c
+++ b/numeric.c
@@ -132,7 +132,8 @@ number may use '_' characters to separate digits.
*/
UV
-Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
+Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
+{
const char *s = start;
STRLEN len = *len_p;
UV value = 0;
@@ -143,6 +144,8 @@ Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
bool overflowed = FALSE;
char bit;
+ PERL_ARGS_ASSERT_GROK_BIN;
+
if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
/* strip off leading b or 0b.
for compatibility silently suffer "b" and "0b" as valid binary
@@ -248,17 +251,19 @@ number may use '_' characters to separate digits.
*/
UV
-Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
+Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
+{
dVAR;
const char *s = start;
STRLEN len = *len_p;
UV value = 0;
NV value_nv = 0;
-
const UV max_div_16 = UV_MAX / 16;
const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
bool overflowed = FALSE;
+ PERL_ARGS_ASSERT_GROK_HEX;
+
if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) {
/* strip off leading x or 0x.
for compatibility silently suffer "x" and "0x" as valid hex numbers.
@@ -363,16 +368,18 @@ number may use '_' characters to separate digits.
*/
UV
-Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) {
+Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
+{
const char *s = start;
STRLEN len = *len_p;
UV value = 0;
NV value_nv = 0;
-
const UV max_div_8 = UV_MAX / 8;
const bool allow_underscores = (bool)(*flags & PERL_SCAN_ALLOW_UNDERSCORES);
bool overflowed = FALSE;
+ PERL_ARGS_ASSERT_GROK_OCT;
+
for (; len-- && *s; s++) {
/* gcc 2.95 optimiser not smart enough to figure that this subtraction
out front allows slicker code. */
@@ -465,6 +472,8 @@ Perl_scan_bin(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
const UV ruv = grok_bin (start, &len, &flags, &rnv);
+ PERL_ARGS_ASSERT_SCAN_BIN;
+
*retlen = len;
return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
}
@@ -476,6 +485,8 @@ Perl_scan_oct(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
const UV ruv = grok_oct (start, &len, &flags, &rnv);
+ PERL_ARGS_ASSERT_SCAN_OCT;
+
*retlen = len;
return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
}
@@ -487,6 +498,8 @@ Perl_scan_hex(pTHX_ const char *start, STRLEN len, STRLEN *retlen)
I32 flags = *retlen ? PERL_SCAN_ALLOW_UNDERSCORES : 0;
const UV ruv = grok_hex (start, &len, &flags, &rnv);
+ PERL_ARGS_ASSERT_SCAN_HEX;
+
*retlen = len;
return (flags & PERL_SCAN_GREATER_THAN_UV_MAX) ? rnv : (NV)ruv;
}
@@ -503,6 +516,9 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
{
#ifdef USE_LOCALE_NUMERIC
dVAR;
+
+ PERL_ARGS_ASSERT_GROK_NUMERIC_RADIX;
+
if (PL_numeric_radix_sv && IN_LOCALE) {
STRLEN len;
const char * const radix = SvPV(PL_numeric_radix_sv, len);
@@ -514,6 +530,9 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
/* always try "." if numeric radix didn't match because
* we may have data from different locales mixed */
#endif
+
+ PERL_ARGS_ASSERT_GROK_NUMERIC_RADIX;
+
if (*sp < send && **sp == '.') {
++*sp;
return TRUE;
@@ -555,6 +574,8 @@ Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
int sawinf = 0;
int sawnan = 0;
+ PERL_ARGS_ASSERT_GROK_NUMBER;
+
while (s < send && isSPACE(*s))
s++;
if (s == send) {
@@ -809,6 +830,9 @@ Perl_my_atof(pTHX_ const char* s)
NV x = 0.0;
#ifdef USE_LOCALE_NUMERIC
dVAR;
+
+ PERL_ARGS_ASSERT_MY_ATOF;
+
if (PL_numeric_local && IN_LOCALE) {
NV y;
@@ -848,6 +872,8 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
I32 old_digit = 0;
I32 sig_digits = 0; /* noof significant digits seen so far */
+ PERL_ARGS_ASSERT_MY_ATOF2;
+
/* There is no point in processing more significant digits
* than the NV can hold. Note that NV_DIG is a lower-bound value,
* while we need an upper-bound value. We add 2 to account for this;