Skip to content

Commit cf54f72

Browse files
authored
Merge pull request #455 from ruby/printf-warnings
Suppress printf format warnings
2 parents 74731d9 + 11b1d8a commit cf54f72

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

ext/openssl/ossl.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,11 @@ ossl_to_der_if_possible(VALUE obj)
268268
/*
269269
* Errors
270270
*/
271-
static VALUE
272-
ossl_make_error(VALUE exc, const char *fmt, va_list args)
271+
VALUE
272+
ossl_make_error(VALUE exc, VALUE str)
273273
{
274-
VALUE str = Qnil;
275274
unsigned long e;
276275

277-
if (fmt) {
278-
str = rb_vsprintf(fmt, args);
279-
}
280276
e = ERR_peek_last_error();
281277
if (e) {
282278
const char *msg = ERR_reason_error_string(e);
@@ -300,10 +296,17 @@ ossl_raise(VALUE exc, const char *fmt, ...)
300296
{
301297
va_list args;
302298
VALUE err;
303-
va_start(args, fmt);
304-
err = ossl_make_error(exc, fmt, args);
305-
va_end(args);
306-
rb_exc_raise(err);
299+
300+
if (fmt) {
301+
va_start(args, fmt);
302+
err = rb_vsprintf(fmt, args);
303+
va_end(args);
304+
}
305+
else {
306+
err = Qnil;
307+
}
308+
309+
rb_exc_raise(ossl_make_error(exc, err));
307310
}
308311

309312
void

ext/openssl/ossl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ int ossl_pem_passwd_cb(char *, int, int, void *);
120120
/*
121121
* ERRor messages
122122
*/
123-
NORETURN(void ossl_raise(VALUE, const char *, ...));
123+
PRINTF_ARGS(NORETURN(void ossl_raise(VALUE, const char *, ...)), 2, 3);
124+
/* Make exception instance from str and OpenSSL error reason string. */
125+
VALUE ossl_make_error(VALUE exc, VALUE str);
124126
/* Clear OpenSSL error queue. If dOSSL is set, rb_warn() them. */
125127
void ossl_clear_error(void);
126128

ext/openssl/ossl_config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ config_load_bio(CONF *conf, BIO *bio)
6060
if (eline <= 0)
6161
ossl_raise(eConfigError, "wrong config format");
6262
else
63-
ossl_raise(eConfigError, "error in line %d", eline);
63+
ossl_raise(eConfigError, "error in line %ld", eline);
6464
}
6565
BIO_free(bio);
6666

ext/openssl/ossl_pkey_ec.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
596596
ossl_raise(rb_eArgError, "wrong number of arguments");
597597
}
598598

599-
if (group == NULL)
600-
ossl_raise(eEC_GROUP, "");
599+
#if !defined(LIKELY) && !defined(RB_LIKELY)
600+
#define LIKELY(x) (x)
601+
#endif
602+
ASSUME(group);
601603
RTYPEDDATA_DATA(self) = group;
602604

603605
return self;

ext/openssl/ossl_ts.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
12231223
ASN1_OBJECT_free(def_policy_id_obj);
12241224
TS_RESP_CTX_free(ctx);
12251225
if (err_msg)
1226-
ossl_raise(eTimestampError, err_msg);
1226+
rb_exc_raise(ossl_make_error(eTimestampError, rb_str_new_cstr(err_msg)));
12271227
if (status)
12281228
rb_jump_tag(status);
12291229
return ret;

0 commit comments

Comments
 (0)