From: Anatol Belski Date: Wed, 3 Jul 2013 09:12:46 +0000 (+0200) Subject: Fixed bug #65184 strftime() returns insufficient-length X-Git-Tag: php-5.5.2RC1~17^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5324416b6514b6de53e7de269bc18b5807701051;p=php Fixed bug #65184 strftime() returns insufficient-length string under multibyte locales The msdn doc states 'strftime returns the number of characters', but prior to VS2012 it seems to have returned the number of bytes. Locale independent. The return is however \0-terminated, so strlen is just fine. The behaivor seems to be persisting in the later VC++ versions as the corresponding MSDN ticket is closed 'by design'. See http://connect.microsoft.com/VisualStudio/feedback/details/766205/vs2012-strftime-has-incorrect-return-value-in-vc-11-with-multibyte-codepages#details --- diff --git a/NEWS b/NEWS index d59945f338..9a78409726 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ PHP NEWS . Fixed bug #65066 (Cli server not responsive when responding with 422 http status code). (Adam) +- DateTime + . Fixed fug #65184 (strftime() returns insufficient-length string under + multibyte locales). (Anatol) + - GD . Fixed #65070 (bgcolor does not use the same format as the input image with imagerotate). (Pierre) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 28ac86b119..0f8822a906 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1678,6 +1678,13 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) break; } } +#if defined(PHP_WIN32) && _MSC_VER >= 1700 + /* VS2012 strftime() returns number of characters, not bytes. + See VC++11 bug id 766205. */ + if (real_len > 0) { + real_len = strlen(buf); + } +#endif timelib_time_dtor(ts); if (!gmt) { diff --git a/ext/date/tests/bug65184.phpt b/ext/date/tests/bug65184.phpt new file mode 100644 index 0000000000..ade020ca36 --- /dev/null +++ b/ext/date/tests/bug65184.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test bug #65184 strftime() returns insufficient-length string under multibyte locales +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +90 85 97 6a 93 fa +===DONE===