summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/bignum.c b/bignum.c
index 3cf4544cb4..0d23189955 100644
--- a/bignum.c
+++ b/bignum.c
@@ -319,6 +319,10 @@ rb_cstr_to_inum(str, base, badcheck)
VALUE z;
BDIGIT *zds;
+ if (!str) {
+ if (badcheck) goto bad;
+ return INT2FIX(0);
+ }
if (badcheck) {
while (ISSPACE(*str)) str++;
}
@@ -501,16 +505,18 @@ rb_str_to_inum(str, base, badcheck)
StringValue(str);
s = RSTRING(str)->ptr;
- len = RSTRING(str)->len;
- if (s[len]) { /* no sentinel somehow */
- char *p = ALLOCA_N(char, len+1);
-
- MEMCPY(p, s, char, len);
- p[len] = '\0';
- s = p;
- }
- if (badcheck && len != strlen(s)) {
- rb_raise(rb_eArgError, "string for Integer contains null byte");
+ if (s) {
+ len = RSTRING(str)->len;
+ if (s[len]) { /* no sentinel somehow */
+ char *p = ALLOCA_N(char, len+1);
+
+ MEMCPY(p, s, char, len);
+ p[len] = '\0';
+ s = p;
+ }
+ if (badcheck && len != strlen(s)) {
+ rb_raise(rb_eArgError, "string for Integer contains null byte");
+ }
}
return rb_cstr_to_inum(s, base, badcheck);
}