Hi Akihiro, On 12.09.2020 09:38, Akihiro Sagawa wrote:
- if(!SysStringLen(str) || *str >= 0x100) + if(!SysStringLen(str)) hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); - else if(res) - hres = return_short(res, *str); + else { + unsigned char buf[2]; + short val = 0; + int n = WideCharToMultiByte(CP_ACP, 0, str, 1, (char*)buf, sizeof(buf), NULL, NULL);
I think we should use WC_ERR_INVALID_CHARS here.
+ switch(n) { + case 1: + val = buf[0]; + break; + case 2: + val = (buf[0] << 8) | buf[1]; + break; + default: + WARN("Failed to convert %x\n", *str); + hres = E_FAIL;
I think it should be MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL).
+ } + if(res && SUCCEEDED(hres)) + hres = return_short(res, val);
return_short already takes care of NULL res, there is no need to check it here. Also, 2-byte variant may overflow short int and your patch will represent them as negative VT_I2. Maybe that's what native does, but it seems like using VT_I4 in such case could be appropriate. Did you verify that with Windows? Thanks, Jacek