On 5 June 2017 at 01:07, Nikolay Sivov <nsivov(a)codeweavers.com> wrote:
+HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name) +{ + DWORD req_size; + + if (!size) + return E_INVALIDARG; + + req_size = strlen(object->classname) + 1; + if (name && *size < req_size) + return E_INVALIDARG; + + *size = req_size; + + if (name) + strcpy(name, object->classname); Note that you already know the string length, so just use memcpy(). (I.e., there's almost never a good reason to use strcpy().)
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index e1091be423..a0dfe6c7d2 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -52,6 +52,42 @@ static D3DRMMATRIX4D identity = { { 0.0f, 0.0f, 0.0f, 1.0f } };
+ +static void test_class_name(IDirect3DRMObject *object, const char *name) +{ + char cname[64] = {0}; + HRESULT hr; + DWORD size; + + hr = IDirect3DRMObject_GetClassName(object, NULL, cname); + ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr); "Got unexpected hr %#x.\n"
+ hr = IDirect3DRMViewport_GetClassName(object, NULL, NULL); + ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr); + + size = 0; + hr = IDirect3DRMObject_GetClassName(object, &size, NULL); + ok(hr == D3DRM_OK, "Cannot get classname size (hr = %x)\n", hr); + ok(size == strlen(name) + 1, "wrong size: %u\n", size); + + size = 1; + hr = IDirect3DRMObject_GetClassName(object, &size, cname); + ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr); + ok(size == 1, "Got size %u.\n", size); + + size = sizeof(cname); + hr = IDirect3DRMObject_GetClassName(object, &size, cname); + ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr); + ok(size == strlen(name) + 1, "wrong size: %u\n", size); + ok(!strcmp(cname, name), "Expected cname to be \"%s\", but got \"%s\"\n", name, cname); + + size = strlen(name); + strcpy(cname, "XXX"); + hr = IDirect3DRMObject_GetClassName(object, &size, cname); + ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr); + ok(size == strlen(name), "wrong size: %u\n", size); + ok(!strcmp(cname, "XXX"), "Expected unchanged buffer, but got \"%s\"\n", cname); +} I would be happier if this printed the line number of the caller on failure, see e.g. check_interface_() in the d3d11 tests.