diff options
Diffstat (limited to 'strftime.c')
| -rw-r--r-- | strftime.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/strftime.c b/strftime.c index a8a688608e..9be4bb9d07 100644 --- a/strftime.c +++ b/strftime.c @@ -66,6 +66,7 @@ #include <math.h> #include "internal.h" +#include "internal/encoding.h" #include "internal/string.h" #include "internal/vm.h" #include "ruby/encoding.h" @@ -170,7 +171,9 @@ resize_buffer(VALUE ftime, char *s, const char **start, const char **endp, ptrdiff_t n, size_t maxsize) { size_t len = s - *start; - size_t nlen = len + n * 2; + size_t need = len + n * 2; + size_t nlen = rb_str_capacity(ftime); + while (nlen < need) nlen <<= 1; if (nlen < len || nlen > maxsize) { return 0; @@ -270,9 +273,9 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, } if (enc && - (enc == rb_usascii_encoding() || - enc == rb_ascii8bit_encoding() || - enc == rb_locale_encoding())) { + (rb_is_usascii_enc(enc) || + rb_is_ascii8bit_enc(enc) || + rb_is_locale_enc(enc))) { enc = NULL; } @@ -929,6 +932,7 @@ rb_strftime(const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, VALUE timev, int gmt) { VALUE result = rb_enc_str_new(0, 0, enc); + ENC_CODERANGE_CLEAR(result); return rb_strftime_with_timespec(result, format, format_len, enc, time, vtm, timev, NULL, gmt, strftime_size_limit(format_len)); @@ -939,6 +943,7 @@ rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt) { VALUE result = rb_enc_str_new(0, 0, enc); + ENC_CODERANGE_CLEAR(result); return rb_strftime_with_timespec(result, format, format_len, enc, time, vtm, Qnil, ts, gmt, strftime_size_limit(format_len)); @@ -982,10 +987,10 @@ vtm2tm_noyear(const struct vtm *vtm, struct tm *result) tm.tm_yday = vtm->yday-1; tm.tm_isdst = vtm->isdst; #if defined(HAVE_STRUCT_TM_TM_GMTOFF) - tm.tm_gmtoff = NUM2LONG(vtm->utc_offset); + tm.tm_gmtoff = 0; #endif #if defined(HAVE_TM_ZONE) - tm.tm_zone = (char *)vtm->zone; + tm.tm_zone = NULL; #endif *result = tm; } |
