Skip to content

Commit

Permalink
Fix JRUBY-6193 by replacing usage of asprintf() with alloca(3)+snprin…
Browse files Browse the repository at this point in the history
…tf(3)
  • Loading branch information
vp-of-awesome committed Jan 26, 2012
1 parent b9c585a commit 69709ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 97 deletions.
80 changes: 0 additions & 80 deletions cext/src/include/ruby/asprintf.h

This file was deleted.

8 changes: 0 additions & 8 deletions cext/src/include/ruby/ruby.h
Expand Up @@ -35,20 +35,12 @@
// Some platform specific includes
#if defined(__WIN32__) || defined(__MINGW32__)
# include "jruby_win32.h"
# include "asprintf.h"
#else
# define RUBY_DLLSPEC
# include <sys/select.h>
# include <pthread.h>
#endif

#if defined (__SVR4) && defined (__sun)
# define HAVE_VA_COPY
# ifndef asprintf
# include "asprintf.h"
# endif
#endif

#ifdef RUBY_EXTCONF_H
#include RUBY_EXTCONF_H
#endif
Expand Down
17 changes: 8 additions & 9 deletions cext/src/object.cpp
Expand Up @@ -19,7 +19,8 @@
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
*/


#include <stdio.h>
#include <stdlib.h>
#include "jruby.h"
#include "ruby.h"
#include "JLocalEnv.h"
Expand Down Expand Up @@ -270,16 +271,14 @@ extern "C" VALUE
rb_any_to_s(VALUE obj)
{
char* buf;
int len = 128, buflen;

if (asprintf(&buf, "#<%s:%p>", rb_obj_classname(obj), (void *) obj) == -1) {
// Could not allocate
return rb_str_new("", 0);
}

VALUE result = rb_str_new_cstr(buf);
free(buf);
do {
buf = (char *) alloca(buflen = len);
len = snprintf(buf, buflen, "#<%s:%p>", rb_obj_classname(obj), (void *) obj);
} while (len >= buflen);

return result;
return rb_str_new_cstr(buf);
}

extern "C" void
Expand Down

0 comments on commit 69709ce

Please sign in to comment.