Skip to content

Fix format specifiers and arguments in com_dotnet #15398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/com_dotnet/com_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ HRESULT php_com_invoke_helper(php_com_dotnet_object *obj, DISPID id_member,

default:
desc = php_win32_error_to_msg(hr);
spprintf(&msg, 0, "Error [0x%08x] %s", hr, desc);
spprintf(&msg, 0, "Error [0x%08lx] %s", hr, desc);
php_win32_error_msg_free(desc);
break;
}
Expand Down Expand Up @@ -639,7 +639,7 @@ zend_result php_com_do_invoke(php_com_dotnet_object *obj, zend_string *name,

if (FAILED(hr)) {
char *winerr = php_win32_error_to_msg(hr);
spprintf(&msg, 0, "Unable to lookup `%s': %s", name, winerr);
spprintf(&msg, 0, "Unable to lookup `%s': %s", ZSTR_VAL(name), winerr);
php_win32_error_msg_free(winerr);
php_com_throw_exception(hr, msg);
efree(msg);
Expand Down
8 changes: 4 additions & 4 deletions ext/com_dotnet/com_dotnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ PHP_METHOD(dotnet, __construct)
if (FAILED(hr)) {
char buf[1024];
char *err = php_win32_error_to_msg(hr);
snprintf(buf, sizeof(buf), "Failed to init .Net runtime [%s] [0x%08x] %s", where, hr, err);
snprintf(buf, sizeof(buf), "Failed to init .Net runtime [%s] [0x%08lx] %s", where, hr, err);
php_win32_error_msg_free(err);
php_com_throw_exception(hr, buf);
RETURN_THROWS();
Expand All @@ -258,7 +258,7 @@ PHP_METHOD(dotnet, __construct)
if (FAILED(hr)) {
char buf[1024];
char *err = php_win32_error_to_msg(hr);
snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] [0x%08x] %s", where, hr, err);
snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] [0x%08lx] %s", where, hr, err);
php_win32_error_msg_free(err);
php_com_throw_exception(hr, buf);
ZVAL_NULL(object);
Expand All @@ -270,7 +270,7 @@ PHP_METHOD(dotnet, __construct)
if (FAILED(hr)) {
char buf[1024];
char *err = php_win32_error_to_msg(hr);
snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] [0x%08x] %s", where, hr, err);
snprintf(buf, sizeof(buf), "Failed to re-init .Net domain [%s] [0x%08lx] %s", where, hr, err);
php_win32_error_msg_free(err);
php_com_throw_exception(hr, buf);
ZVAL_NULL(object);
Expand Down Expand Up @@ -344,7 +344,7 @@ PHP_METHOD(dotnet, __construct)
if (ret == FAILURE) {
char buf[1024];
char *err = php_win32_error_to_msg(hr);
snprintf(buf, sizeof(buf), "Failed to instantiate .Net object [%s] [0x%08x] %s", where, hr, err);
snprintf(buf, sizeof(buf), "Failed to instantiate .Net object [%s] [0x%08lx] %s", where, hr, err);
php_win32_error_msg_free(err);
php_com_throw_exception(hr, buf);
RETURN_THROWS();
Expand Down
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_typeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ bool php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, bool p
/* first element is the function name */
SysFreeString(names[0]);

php_printf("\t/* DISPID=%d */\n", func->memid);
php_printf("\t/* DISPID=%ld */\n", func->memid);

if (func->elemdescFunc.tdesc.vt != VT_VOID) {
php_printf("\t/* %s [%d] */\n",
Expand Down
18 changes: 9 additions & 9 deletions ext/com_dotnet/com_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static inline void trace(char *fmt, ...)
va_list ap;
char buf[4096];

snprintf(buf, sizeof(buf), "T=%08x ", GetCurrentThreadId());
snprintf(buf, sizeof(buf), "T=%08lx ", GetCurrentThreadId());
OutputDebugString(buf);

va_start(ap, fmt);
Expand All @@ -70,7 +70,7 @@ static inline void trace(char *fmt, ...)
if (COMG(rshutdown_started)) { \
trace(" PHP Object:%p (name:unknown) %s\n", Z_OBJ(disp->object), methname); \
} else { \
trace(" PHP Object:%p (name:%s) %s\n", Z_OBJ(disp->object), Z_OBJCE(disp->object)->name->val, methname); \
trace(" PHP Object:%p (name:%s) %s\n", Z_OBJ(disp->object), ZSTR_VAL(Z_OBJCE(disp->object)->name), methname); \
} \
if (GetCurrentThreadId() != disp->engine_thread) { \
return RPC_E_WRONG_THREAD; \
Expand Down Expand Up @@ -109,7 +109,7 @@ static ULONG STDMETHODCALLTYPE disp_release(IDispatchEx *This)
FETCH_DISP("Release");

ret = InterlockedDecrement(&disp->refcount);
trace("-- refcount now %d\n", ret);
trace("-- refcount now %lu\n", ret);
if (ret == 0) {
/* destroy it */
disp_destructor(disp);
Expand Down Expand Up @@ -201,7 +201,7 @@ static HRESULT STDMETHODCALLTYPE disp_getdispid(

name = php_com_olestring_to_string(bstrName, COMG(code_page));

trace("Looking for %s, namelen=%d in %p\n", ZSTR_VAL(name), ZSTR_LEN(name), disp->name_to_dispid);
trace("Looking for %s, namelen=%lu in %p\n", ZSTR_VAL(name), ZSTR_LEN(name), disp->name_to_dispid);

/* Lookup the name in the hash */
if ((tmp = zend_hash_find(disp->name_to_dispid, name)) != NULL) {
Expand Down Expand Up @@ -235,7 +235,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex(
if (NULL != (name = zend_hash_index_find(disp->dispid_to_name, id))) {
/* TODO: add support for overloaded objects */

trace("-- Invoke: %d %20s [%d] flags=%08x args=%d\n", id, Z_STRVAL_P(name), Z_STRLEN_P(name), wFlags, pdp->cArgs);
trace("-- Invoke: %ld %20s [%lu] flags=%08x args=%u\n", id, Z_STRVAL_P(name), Z_STRLEN_P(name), wFlags, pdp->cArgs);

/* convert args into zvals.
* Args are in reverse order */
Expand All @@ -246,7 +246,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex(

arg = &pdp->rgvarg[ pdp->cArgs - 1 - i];

trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg));
trace("alloc zval for arg %u VT=%08x\n", i, V_VT(arg));

php_com_wrap_variant(&params[i], arg, COMG(code_page));
}
Expand Down Expand Up @@ -275,7 +275,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex(
VARIANT *srcvar = &obj->v;
VARIANT *dstvar = &pdp->rgvarg[ pdp->cArgs - 1 - i];
if ((V_VT(dstvar) & VT_BYREF) && obj->modified ) {
trace("percolate modified value for arg %d VT=%08x\n", i, V_VT(dstvar));
trace("percolate modified value for arg %u VT=%08x\n", i, V_VT(dstvar));
php_com_copy_variant(dstvar, srcvar);
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ static HRESULT STDMETHODCALLTYPE disp_invokeex(
}

} else {
trace("InvokeEx: I don't support DISPID=%d\n", id);
trace("InvokeEx: I don't support DISPID=%ld\n", id);
}

return ret;
Expand Down Expand Up @@ -508,7 +508,7 @@ static php_dispatchex *disp_constructor(zval *object)
{
php_dispatchex *disp = (php_dispatchex*)CoTaskMemAlloc(sizeof(php_dispatchex));

trace("constructing a COM wrapper for PHP object %p (%s)\n", object, Z_OBJCE_P(object)->name);
trace("constructing a COM wrapper for PHP object %p (%s)\n", object, ZSTR_VAL(Z_OBJCE_P(object)->name));

if (disp == NULL)
return NULL;
Expand Down
15 changes: 15 additions & 0 deletions ext/com_dotnet/tests/lookup_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Property name lookup error
--EXTENSIONS--
com_dotnet
--FILE--
<?php
$dict = new COM("Scripting.Dictionary");
try {
$dict->unknownProperty;
} catch (com_exception $ex) {
echo $ex->getMessage(), "\n";
}
?>
--EXPECTF--
Unable to lookup `unknownProperty': %s
Loading