From ec70309ffa6994a01b0f1b53ff05526ef9d388b5 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 10 May 2017 23:18:07 +0000 Subject: [PATCH] process.c: temporary string for buffer * process.c (obj2uid, obj2gid): use temporary string as the buffer instead of `rb_alloc_tmp_buffer`, which is `NODE_ALLOCA` since r51492. [ruby-core:81084] [Bug #13554] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/process.c b/process.c index 9191051f99..27a12f8635 100644 --- a/process.c +++ b/process.c @@ -172,7 +172,7 @@ static void check_gid_switch(void); # define PREPARE_GETPWNAM \ VALUE getpw_buf = 0 # define FINISH_GETPWNAM \ - ALLOCV_END(getpw_buf) + (getpw_buf ? (void)rb_str_resize(getpw_buf, 0) : (void)0) # define OBJ2UID1(id) obj2uid((id), &getpw_buf) # define OBJ2UID(id) obj2uid0(id) static rb_uid_t obj2uid(VALUE id, VALUE *getpw_buf); @@ -214,7 +214,7 @@ static rb_uid_t obj2uid(VALUE id); # define PREPARE_GETGRNAM \ VALUE getgr_buf = 0 # define FINISH_GETGRNAM \ - ALLOCV_END(getgr_buf) + (getgr_buf ? (void)rb_str_resize(getgr_buf, 0) : (void)0) # define OBJ2GID1(id) obj2gid((id), &getgr_buf) # define OBJ2GID(id) obj2gid0(id) static rb_gid_t obj2gid(VALUE id, VALUE *getgr_buf); @@ -5033,18 +5033,17 @@ obj2uid(VALUE id if (!*getpw_tmp) { getpw_buf_len = GETPW_R_SIZE_INIT; if (getpw_buf_len < 0) getpw_buf_len = GETPW_R_SIZE_DEFAULT; - getpw_buf = rb_alloc_tmp_buffer(getpw_tmp, getpw_buf_len); - } - else { - getpw_buf = RSTRING_PTR(*getpw_tmp); - getpw_buf_len = rb_str_capacity(*getpw_tmp); + *getpw_tmp = rb_str_tmp_new(getpw_buf_len); } + getpw_buf = RSTRING_PTR(*getpw_tmp); + getpw_buf_len = rb_str_capacity(*getpw_tmp); + rb_str_set_len(*getpw_tmp, getpw_buf_len); errno = ERANGE; /* gepwnam_r() on MacOS X doesn't set errno if buffer size is insufficient */ while (getpwnam_r(usrname, &pwbuf, getpw_buf, getpw_buf_len, &pwptr)) { int e = errno; if (e != ERANGE || getpw_buf_len >= GETPW_R_SIZE_LIMIT) { - rb_free_tmp_buffer(getpw_tmp); + rb_str_resize(*getpw_tmp, 0); rb_syserr_fail(e, "getpwnam_r"); } rb_str_modify_expand(*getpw_tmp, getpw_buf_len); @@ -5112,18 +5111,17 @@ obj2gid(VALUE id if (!*getgr_tmp) { getgr_buf_len = GETGR_R_SIZE_INIT; if (getgr_buf_len < 0) getgr_buf_len = GETGR_R_SIZE_DEFAULT; - getgr_buf = rb_alloc_tmp_buffer(getgr_tmp, getgr_buf_len); - } - else { - getgr_buf = RSTRING_PTR(*getgr_tmp); - getgr_buf_len = rb_str_capacity(*getgr_tmp); + *getgr_tmp = rb_str_tmp_new(getgr_buf_len); } + getgr_buf = RSTRING_PTR(*getgr_tmp); + getgr_buf_len = rb_str_capacity(*getgr_tmp); + rb_str_set_len(*getgr_tmp, getgr_buf_len); errno = ERANGE; /* gegrnam_r() on MacOS X doesn't set errno if buffer size is insufficient */ while (getgrnam_r(grpname, &grbuf, getgr_buf, getgr_buf_len, &grptr)) { int e = errno; if (e != ERANGE || getgr_buf_len >= GETGR_R_SIZE_LIMIT) { - rb_free_tmp_buffer(getgr_tmp); + rb_str_resize(*getgr_tmp, 0); rb_syserr_fail(e, "getgrnam_r"); } rb_str_modify_expand(*getgr_tmp, getgr_buf_len);