summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 06:55:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-24 06:55:09 +0000
commit92261511b662c3f690f2c1dd70ab36161c676737 (patch)
treee9cba973aaaee79b5785c98d0765743cb3005521 /string.c
parent9e1624cfe8880fc018e34327c77669f2f4e5b100 (diff)
string.c: for small crypt_data
* string.c (rb_str_crypt): struct crypt_data defined in missing/crypt.h is small enough. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/string.c b/string.c
index bb86cb6b7f..bd4a481203 100644
--- a/string.c
+++ b/string.c
@@ -8722,8 +8722,14 @@ rb_str_oct(VALUE str)
static VALUE
rb_str_crypt(VALUE str, VALUE salt)
{
+#undef LARGE_CRYPT_DATA
#ifdef HAVE_CRYPT_R
+# if defined SIZEOF_CRYPT_DATA && SIZEOF_CRYPT_DATA <= 256
+ struct crypt_data cdata, *const data = &cdata;
+# else
+# undef LARGE_CRYPT_DATA
struct crypt_data *data = ALLOC(struct crypt_data);
+# endif
#else
extern char *crypt(const char *, const char *);
#endif
@@ -8762,7 +8768,7 @@ rb_str_crypt(VALUE str, VALUE salt)
res = crypt(s, saltp);
#endif
if (!res) {
-#ifdef HAVE_CRYPT_R
+#ifdef LARGE_CRYPT_DATA
int err = errno;
xfree(data);
errno = err;
@@ -8770,7 +8776,7 @@ rb_str_crypt(VALUE str, VALUE salt)
rb_sys_fail("crypt");
}
result = rb_str_new_cstr(res);
-#ifdef HAVE_CRYPT_R
+#ifdef LARGE_CRYPT_DATA
xfree(data);
#endif
FL_SET_RAW(result, OBJ_TAINTED_RAW(str) | OBJ_TAINTED_RAW(salt));