<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2014-10-20 17:00 GMT+08:00 Piotr Caban <span dir="ltr"><<a href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 10/19/14 17:44, Shuai Meng wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+    newstr = SysAllocStringLen(NULL, 1023);<br>
</blockquote></span>
You need to allocate correct length string. First argument should be used here. You're also leaking the string in error-handling paths.</blockquote><div> You mean I should replace 1023 with the final number of first argument? Seems good. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
+    switch(V_VT(arg + 1)) {<br>
+    case VT_NULL:<br>
+        return MAKE_VBSERROR(VBSE_ILLEGAL_<u></u>NULL_USE);<br>
+    case VT_BSTR:<br>
+        str = V_BSTR(arg + 1);<br>
+        break;<br>
+    case  VT_ARRAY|VT_BYREF|VT_VARIANT:<br>
+        return DISP_E_TYPEMISMATCH;<br>
+    default:<br>
+        hres = to_short(arg + 1, &tmp);<br>
+        if(FAILED(hres))<br>
+            return hres;<br>
+        str[0] = (char)tmp;<br>
</blockquote></span>
Please add a test with second argument larger then 256. It would be also interesting to see a test with second argument being BSTR with first character out of ASCII range.</blockquote><div> In fact it is hard to check what String returns when character is larger than 256 even below 256. For example, String(1,0) returns an empty string on xp, but Eval(String(1,0) = "") will return false, we all know 0 represents '\0' in ASCII which is not a print character. This is the same situation when the second argument is negative number. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> Please also check what happens if V_BSTR(arg+1)==NULL.<br></blockquote><div>I have added such test: </div><div><span style="color:rgb(0,0,0);font-family:'Courier New',Courier,monospace;font-size:14px;white-space:pre-wrap">Call testStringError(2, Null, 94)</span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+    hres = to_short(arg, &len);<span class=""><br>
+    if(FAILED(hres))<br>
+        return hres;<br></span>
+    if(len <  0)<br>
+        return MAKE_VBSERROR(VBSE_ILLEGAL_<u></u>FUNC_CALL);<span class=""><br>
+    else if(len == 0)<br>
+        newstr = '\0';<br></span>
+    else if(len > 1023)<br>
+        len = 1023;<br>
</blockquote>
I guess that first argument is probably an integer. </blockquote><div> Do you mean we don't need  to_short(arg, &len)?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The length of produced string is probably also not limited to 1023 characters.<br></blockquote><div>I have answered this question in the reply to Nikolay~</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Thanks,<br>
Piotr<br>
<br>
<br>
</blockquote></div>Thanks for commenting Piotr.</div></div>