aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-29 00:37:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-29 00:37:12 +0000
commit374fcff28ca08cdabd66d1fb939367ed45df0ccd (patch)
tree1e78c89d66f979f66a86b91d9029a274dafc9a56 /error.c
parent6bb52d8026b8c5b27f0f48dcfe7ac4e6e62a7428 (diff)
downloadruby-374fcff28ca08cdabd66d1fb939367ed45df0ccd.tar.gz
error.c: simplify message building
* error.c (syserr_initialize): simplify message building and get rid of potential invalid byte sequence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/error.c b/error.c
index 241413c738..375c2ff5a7 100644
--- a/error.c
+++ b/error.c
@@ -1341,7 +1341,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
char *strerror();
#endif
const char *err;
- VALUE mesg, error, func;
+ VALUE mesg, error, func, errmsg;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
@@ -1365,25 +1365,17 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
else err = "unknown error";
+
+ errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding());
if (!NIL_P(mesg)) {
- rb_encoding *le = rb_locale_encoding();
VALUE str = StringValue(mesg);
- rb_encoding *me = rb_enc_get(mesg);
-
- if (NIL_P(func))
- mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
- else
- mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
- if (le != me && rb_enc_asciicompat(me)) {
- le = me;
- }/* else assume err is non ASCII string. */
- OBJ_INFECT(mesg, str);
- rb_enc_associate(mesg, le);
- }
- else {
- mesg = rb_str_new2(err);
- rb_enc_associate(mesg, rb_locale_encoding());
+
+ if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
+ rb_str_catf(errmsg, " - %"PRIsVALUE, str);
+ OBJ_INFECT(errmsg, mesg);
}
+ mesg = errmsg;
+
rb_call_super(1, &mesg);
rb_iv_set(self, "errno", error);
return self;