diff options
author | Eric Wong <normalperson@yhbt.net> | 2014-02-15 22:29:49 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2014-02-15 22:29:49 +0000 |
commit | a3562a9a200a1ffd31c472652265bbb234589eb0 (patch) | |
tree | aa1b36f5cee34fac92415da1b3b192a9fc6b1ead /ext | |
parent | 115bbc59f6277c005fe3dbb6d1e192464bb0821d (diff) | |
download | clogger-a3562a9a200a1ffd31c472652265bbb234589eb0.tar.gz |
If we convert an object to string, there is a potential the compiler may optimize away the converted string if escaping is needed. Prevent that with RB_GC_GUARD.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/clogger_ext/clogger.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index ed01534..8b05c34 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -166,10 +166,11 @@ static inline int need_escape(unsigned c) } /* we are encoding-agnostic, clients can send us all sorts of junk */ -static VALUE byte_xs_str(VALUE from) +static VALUE byte_xs(VALUE obj) { static const char esc[] = "0123456789ABCDEF"; unsigned char *new_ptr; + VALUE from = rb_obj_as_string(obj); const unsigned char *ptr = (const unsigned char *)RSTRING_PTR(from); long len = RSTRING_LEN(from); long new_len = len; @@ -203,14 +204,10 @@ static VALUE byte_xs_str(VALUE from) } assert(RSTRING_PTR(rv)[RSTRING_LEN(rv)] == '\0'); + RB_GC_GUARD(from); return rv; } -static VALUE byte_xs(VALUE from) -{ - return byte_xs_str(rb_obj_as_string(from)); -} - static void clogger_mark(void *ptr) { struct clogger *c = ptr; |