From: Alan Brown Date: Fri, 9 Nov 2001 14:20:28 +0000 (+0000) Subject: Not all components populate every field in the ExceptInfo structure. Thus we sometime... X-Git-Tag: ChangeLog~379 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ee38d9d75f02b604106887b2548d30b7c913414;p=php Not all components populate every field in the ExceptInfo structure. Thus we sometimes would try to convert NULL strings and see php_OLECHAR_to_char errors while displaying Exception information. This version is a little smarter about the member derefencing and the resulting error string. --- diff --git a/ext/com/COM.c b/ext/com/COM.c index 794a71ae16..01665528df 100644 --- a/ext/com/COM.c +++ b/ext/com/COM.c @@ -133,20 +133,32 @@ PHPAPI HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DIS if (FAILED(hr)) { switch (hr) { case DISP_E_EXCEPTION: { - int srclen; - char *src = php_OLECHAR_to_char(ExceptInfo.bstrSource, &srclen, codepage TSRMLS_CC); - int desclen; - char *desc = php_OLECHAR_to_char(ExceptInfo.bstrDescription, &desclen, codepage TSRMLS_CC); - + int srclen=0; + char *src=estrdup(""); + int desclen=0; + char *desc=estrdup(""); + + if (ExceptInfo.bstrSource) + { + src = php_OLECHAR_to_char(ExceptInfo.bstrSource, &srclen, codepage TSRMLS_CC); + SysFreeString(ExceptInfo.bstrSource); + } + if (ExceptInfo.bstrDescription) + { + desc = php_OLECHAR_to_char(ExceptInfo.bstrDescription, &desclen, codepage TSRMLS_CC); + SysFreeString(ExceptInfo.bstrDescription); + } + *ErrString = pemalloc(srclen+desclen+50, 1); sprintf(*ErrString, "Source: %s Description: %s", src, desc); efree(src); efree(desc); - SysFreeString(ExceptInfo.bstrSource); - SysFreeString(ExceptInfo.bstrDescription); - SysFreeString(ExceptInfo.bstrHelpFile); + + if (ExceptInfo.bstrHelpFile) + { + SysFreeString(ExceptInfo.bstrHelpFile); + } } - break; case DISP_E_PARAMNOTFOUND: case DISP_E_TYPEMISMATCH: *ErrString = pemalloc(25, 1); diff --git a/ext/rpc/com/com_wrapper.c b/ext/rpc/com/com_wrapper.c index 794a71ae16..01665528df 100644 --- a/ext/rpc/com/com_wrapper.c +++ b/ext/rpc/com/com_wrapper.c @@ -133,20 +133,32 @@ PHPAPI HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DIS if (FAILED(hr)) { switch (hr) { case DISP_E_EXCEPTION: { - int srclen; - char *src = php_OLECHAR_to_char(ExceptInfo.bstrSource, &srclen, codepage TSRMLS_CC); - int desclen; - char *desc = php_OLECHAR_to_char(ExceptInfo.bstrDescription, &desclen, codepage TSRMLS_CC); - + int srclen=0; + char *src=estrdup(""); + int desclen=0; + char *desc=estrdup(""); + + if (ExceptInfo.bstrSource) + { + src = php_OLECHAR_to_char(ExceptInfo.bstrSource, &srclen, codepage TSRMLS_CC); + SysFreeString(ExceptInfo.bstrSource); + } + if (ExceptInfo.bstrDescription) + { + desc = php_OLECHAR_to_char(ExceptInfo.bstrDescription, &desclen, codepage TSRMLS_CC); + SysFreeString(ExceptInfo.bstrDescription); + } + *ErrString = pemalloc(srclen+desclen+50, 1); sprintf(*ErrString, "Source: %s Description: %s", src, desc); efree(src); efree(desc); - SysFreeString(ExceptInfo.bstrSource); - SysFreeString(ExceptInfo.bstrDescription); - SysFreeString(ExceptInfo.bstrHelpFile); + + if (ExceptInfo.bstrHelpFile) + { + SysFreeString(ExceptInfo.bstrHelpFile); + } } - break; case DISP_E_PARAMNOTFOUND: case DISP_E_TYPEMISMATCH: *ErrString = pemalloc(25, 1);