Sebastian Lackner : jscript: Allocate string of correct size in Date toTimeString method.

Alexandre Julliard julliard at winehq.org
Fri Sep 9 10:09:03 CDT 2016


Module: wine
Branch: master
Commit: fd07a1572762a05de8f1269e2b1287af6a9c71e8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fd07a1572762a05de8f1269e2b1287af6a9c71e8

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Thu Sep  8 23:54:54 2016 +0200

jscript: Allocate string of correct size in Date toTimeString method.

Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/date.c       | 15 +++++++--------
 dlls/jscript/tests/api.js |  6 ++++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c
index b6997ab..fdc3051 100644
--- a/dlls/jscript/date.c
+++ b/dlls/jscript/date.c
@@ -850,6 +850,7 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
         ':','%','0','2','d',' ','U','T','C',0 };
     DateInstance *date;
     jsstr_t *date_str;
+    WCHAR buf[32];
     DOUBLE time;
     WCHAR sign;
     int offset;
@@ -868,12 +869,6 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
     time = local_time(date->time, date);
 
     if(r) {
-        WCHAR *ptr;
-
-        date_str = jsstr_alloc_buf(17, &ptr);
-        if(!date_str)
-            return E_OUTOFMEMORY;
-
         offset = date->bias +
             daylight_saving_ta(time, date);
 
@@ -884,13 +879,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
         else sign = '-';
 
         if(offset)
-            sprintfW(ptr, formatW, (int)hour_from_time(time),
+            sprintfW(buf, formatW, (int)hour_from_time(time),
                     (int)min_from_time(time), (int)sec_from_time(time),
                     sign, offset/60, offset%60);
         else
-            sprintfW(ptr, formatUTCW, (int)hour_from_time(time),
+            sprintfW(buf, formatUTCW, (int)hour_from_time(time),
                     (int)min_from_time(time), (int)sec_from_time(time));
 
+        date_str = jsstr_alloc(buf);
+        if(!date_str)
+            return E_OUTOFMEMORY;
+
         *r = jsval_string(date_str);
     }
     return S_OK;
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 43f7a19..083da93 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -2147,9 +2147,11 @@ ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 201
         "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400"));
 
 tmp = (new Date()).toLocaleDateString();
-ok(tmp.charCodeAt(tmp.length-1) != 0, "invalid null byte");
+ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
 tmp = (new Date()).toLocaleTimeString();
-ok(tmp.charCodeAt(tmp.length-1) != 0, "invalid null byte");
+ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
+tmp = (new Date()).toTimeString();
+ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
 
 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);




More information about the wine-cvs mailing list