summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-10 11:45:14 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-10 11:45:14 +0000
commit565d568a45855f138364c414ea266b3fd80ec05c (patch)
tree4de0568b654911049defc04edd184cb7bb0d34dd /ext/openssl
parent73fc780998054e9ca4835b784b6fc9051f83332f (diff)
merge revision(s) 44572,44578,44591,44592: [Backport #9490]
ext: use rb_sprintf() and rb_vsprintf() with PRIsVALUE git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@44903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 43ccf4c3fd..3961d3ea33 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -293,10 +293,9 @@ ossl_to_der_if_possible(VALUE obj)
static VALUE
ossl_make_error(VALUE exc, const char *fmt, va_list args)
{
- char buf[BUFSIZ];
+ VALUE str = Qnil;
const char *msg;
long e;
- int len = 0;
#ifdef HAVE_ERR_PEEK_LAST_ERROR
e = ERR_peek_last_error();
@@ -304,14 +303,19 @@ ossl_make_error(VALUE exc, const char *fmt, va_list args)
e = ERR_peek_error();
#endif
if (fmt) {
- len = vsnprintf(buf, BUFSIZ, fmt, args);
+ str = rb_vsprintf(fmt, args);
}
- if (len < BUFSIZ && e) {
+ if (e) {
if (dOSSL == Qtrue) /* FULL INFO */
msg = ERR_error_string(e, NULL);
else
msg = ERR_reason_error_string(e);
- len += snprintf(buf+len, BUFSIZ-len, "%s%s", (len ? ": " : ""), msg);
+ if (NIL_P(str)) {
+ str = rb_str_new_cstr(msg);
+ }
+ else {
+ rb_str_cat2(rb_str_cat2(str, ": "), msg);
+ }
}
if (dOSSL == Qtrue){ /* show all errors on the stack */
while ((e = ERR_get_error()) != 0){
@@ -320,8 +324,8 @@ ossl_make_error(VALUE exc, const char *fmt, va_list args)
}
ERR_clear_error();
- if(len > BUFSIZ) len = rb_long2int(strlen(buf));
- return rb_exc_new(exc, buf, len);
+ if (NIL_P(str)) str = rb_str_new(0, 0);
+ return rb_exc_new3(exc, str);
}
void