aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/string.c b/string.c
index 27d40fbe26..35d3fad747 100644
--- a/string.c
+++ b/string.c
@@ -2161,30 +2161,27 @@ str_fill_term(VALUE str, char *s, long len, int termlen)
void
rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int termlen)
{
- long capa = str_capacity(str, oldtermlen) + oldtermlen;
+ size_t oldbufsize = str_capacity(str, oldtermlen) + oldtermlen;
long len = RSTRING_LEN(str);
- assert(capa >= len);
- if (capa - len < termlen) {
- rb_check_lockedtmp(str);
- str_make_independent_expand(str, len, 0L, termlen);
- }
- else if (str_dependent_p(str)) {
- if (termlen > oldtermlen)
+ if (termlen > oldtermlen) {
+ if (str_dependent_p(str)) {
+ rb_check_lockedtmp(str);
str_make_independent_expand(str, len, 0L, termlen);
- }
- else {
- if (!STR_EMBED_P(str)) {
- /* modify capa instead of realloc */
- assert(!FL_TEST((str), STR_SHARED));
- RSTRING(str)->as.heap.aux.capa = capa - termlen;
}
- if (termlen > oldtermlen) {
+ else if (oldbufsize - len < (size_t)termlen) {
+ rb_check_lockedtmp(str);
+ RESIZE_CAPA_TERM(str, len, termlen);
+ }
+ else
TERM_FILL(RSTRING_PTR(str) + len, termlen);
+ }
+ else {
+ if (!FL_TEST(str, STR_))
+ if (!STR_EMBED_P(str) && !FL_TEST(str, STR_SHARED|STR_NOFREE)) {
+ RSTRING(str)->as.heap.aux.capa = oldbufsize - termlen;
}
}
-
- return;
}
static char *
@@ -8809,7 +8806,7 @@ rb_str_crypt(VALUE str, VALUE salt)
struct crypt_data cdata, *const data = &cdata;
# else
# define LARGE_CRYPT_DATA
- struct crypt_data *data = ALLOC(struct crypt_data);
+ struct crypt_data *data;
# endif
#else
extern char *crypt(const char *, const char *);
@@ -8841,6 +8838,9 @@ rb_str_crypt(VALUE str, VALUE salt)
}
#endif
#ifdef HAVE_CRYPT_R
+# ifdef LARGE_CRYPT_DATA
+ data = ALLOC(struct crypt_data);
+# endif
# ifdef HAVE_STRUCT_CRYPT_DATA_INITIALIZED
data->initialized = 0;
# endif