From 7f8e30bd1a1cfbe7ecf7ec7d358beba126adaeb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B3zef=20Kucia?= Date: Thu, 19 Oct 2017 10:07:29 +0200 Subject: [PATCH] wined3d: Use ARRAY_SIZE(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/context.c | 2 +- dlls/wined3d/device.c | 8 ++++---- dlls/wined3d/directx.c | 27 ++++++++++++--------------- dlls/wined3d/shader_sm4.c | 4 ++-- dlls/wined3d/state.c | 2 +- dlls/wined3d/stateblock.c | 12 ++++++------ dlls/wined3d/surface.c | 2 +- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index a2c0ba4080c..ba9e19c06ec 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -289,7 +289,7 @@ static void context_dump_fbo_attachment(const struct wined3d_gl_info *gl_info, G unsigned int i; tex_type_str = NULL; - for (i = 0; i < sizeof(texture_type) / sizeof(*texture_type); ++i) + for (i = 0; i < ARRAY_SIZE(texture_type); ++i) { if (!gl_info->supported[texture_type[i].extension]) continue; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 31955badb10..994c4b1a144 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -2032,7 +2032,7 @@ void CDECL wined3d_device_set_sampler_state(struct wined3d_device *device, if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3) sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS); - if (sampler_idx >= sizeof(device->state.sampler_states) / sizeof(*device->state.sampler_states)) + if (sampler_idx >= ARRAY_SIZE(device->state.sampler_states)) { WARN("Invalid sampler %u.\n", sampler_idx); return; /* Windows accepts overflowing this array ... we do not. */ @@ -2067,7 +2067,7 @@ DWORD CDECL wined3d_device_get_sampler_state(const struct wined3d_device *device if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3) sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS); - if (sampler_idx >= sizeof(device->state.sampler_states) / sizeof(*device->state.sampler_states)) + if (sampler_idx >= ARRAY_SIZE(device->state.sampler_states)) { WARN("Invalid sampler %u.\n", sampler_idx); return 0; /* Windows accepts overflowing this array ... we do not. */ @@ -3423,7 +3423,7 @@ HRESULT CDECL wined3d_device_set_texture(struct wined3d_device *device, stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS); /* Windows accepts overflowing this array... we do not. */ - if (stage >= sizeof(device->state.textures) / sizeof(*device->state.textures)) + if (stage >= ARRAY_SIZE(device->state.textures)) { WARN("Ignoring invalid stage %u.\n", stage); return WINED3D_OK; @@ -3467,7 +3467,7 @@ struct wined3d_texture * CDECL wined3d_device_get_texture(const struct wined3d_d if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3) stage -= (WINED3DVERTEXTEXTURESAMPLER0 - MAX_FRAGMENT_SAMPLERS); - if (stage >= sizeof(device->state.textures) / sizeof(*device->state.textures)) + if (stage >= ARRAY_SIZE(device->state.textures)) { WARN("Ignoring invalid stage %u.\n", stage); return NULL; /* Windows accepts overflowing this array ... we do not. */ diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index da66ad36fd2..e06001703ee 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -580,7 +580,7 @@ static void test_pbo_functionality(struct wined3d_gl_info *gl_info) 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff, 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff }; - unsigned int check[sizeof(pattern) / sizeof(pattern[0])]; + unsigned int check[ARRAY_SIZE(pattern)]; /* No PBO -> No point in testing them. */ if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return; @@ -1525,7 +1525,7 @@ static const struct driver_version_information *get_driver_version_info(enum win unsigned int i; TRACE("Looking up version info for driver=%d driver_model=%d\n", driver, driver_model); - for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) + for (i = 0; i < ARRAY_SIZE(driver_version_table); ++i) { const struct driver_version_information *entry = &driver_version_table[i]; @@ -1545,7 +1545,7 @@ static const struct gpu_description *get_gpu_description(enum wined3d_pci_vendor { unsigned int i; - for (i = 0; i < (sizeof(gpu_description_table) / sizeof(*gpu_description_table)); ++i) + for (i = 0; i < ARRAY_SIZE(gpu_description_table); ++i) { if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].card) return &gpu_description_table[i]; @@ -1731,7 +1731,7 @@ static void fixup_extensions(struct wined3d_gl_info *gl_info, struct wined3d_cap { unsigned int i; - for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i) + for (i = 0; i < ARRAY_SIZE(quirk_table); ++i) { if (!quirk_table[i].match(gl_info, ctx, gl_renderer, gl_vendor, card_vendor, device)) continue; TRACE("Applying driver quirk \"%s\".\n", quirk_table[i].description); @@ -2479,16 +2479,16 @@ static const struct card_vendor_table[] = { {HW_VENDOR_AMD, "AMD", amd_gl_vendor_table, - sizeof(amd_gl_vendor_table) / sizeof(*amd_gl_vendor_table), + ARRAY_SIZE(amd_gl_vendor_table), card_fallback_amd}, {HW_VENDOR_NVIDIA, "Nvidia", nvidia_gl_vendor_table, - sizeof(nvidia_gl_vendor_table) / sizeof(*nvidia_gl_vendor_table), + ARRAY_SIZE(nvidia_gl_vendor_table), card_fallback_nvidia}, {HW_VENDOR_VMWARE, "VMware", vmware_gl_vendor_table, - sizeof(vmware_gl_vendor_table) / sizeof(*vmware_gl_vendor_table), + ARRAY_SIZE(vmware_gl_vendor_table), card_fallback_amd}, {HW_VENDOR_INTEL, "Intel", intel_gl_vendor_table, - sizeof(intel_gl_vendor_table) / sizeof(*intel_gl_vendor_table), + ARRAY_SIZE(intel_gl_vendor_table), card_fallback_intel}, }; @@ -2550,7 +2550,7 @@ static enum wined3d_pci_device wined3d_guess_card(const struct shader_caps *shad enum wined3d_d3d_level d3d_level = d3d_level_from_caps(shader_caps, fragment_caps, glsl_version); enum wined3d_pci_device device; - for (i = 0; i < (sizeof(card_vendor_table) / sizeof(*card_vendor_table)); ++i) + for (i = 0; i < ARRAY_SIZE(card_vendor_table); ++i) { if (card_vendor_table[i].card_vendor != *card_vendor) continue; @@ -3975,13 +3975,11 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, ERR("Received a NULL GL_EXTENSIONS.\n"); return FALSE; } - parse_extension_string(gl_info, gl_extensions, gl_extension_map, - sizeof(gl_extension_map) / sizeof(*gl_extension_map)); + parse_extension_string(gl_info, gl_extensions, gl_extension_map, ARRAY_SIZE(gl_extension_map)); } else { - enumerate_gl_extensions(gl_info, gl_extension_map, - sizeof(gl_extension_map) / sizeof(*gl_extension_map)); + enumerate_gl_extensions(gl_info, gl_extension_map, ARRAY_SIZE(gl_extension_map)); } hdc = wglGetCurrentDC(); @@ -3991,8 +3989,7 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, if (!WGL_Extensions) WARN("WGL extensions not supported.\n"); else - parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map, - sizeof(wgl_extension_map) / sizeof(*wgl_extension_map)); + parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map, ARRAY_SIZE(wgl_extension_map)); for (i = 0; i < ARRAY_SIZE(core_extensions); ++i) { diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c index e3d74e274ef..a04debe264d 100644 --- a/dlls/wined3d/shader_sm4.c +++ b/dlls/wined3d/shader_sm4.c @@ -1158,7 +1158,7 @@ static const struct wined3d_sm4_opcode_info *get_opcode_info(enum wined3d_sm4_op { unsigned int i; - for (i = 0; i < sizeof(opcode_table) / sizeof(*opcode_table); ++i) + for (i = 0; i < ARRAY_SIZE(opcode_table); ++i) { if (opcode == opcode_table[i].opcode) return &opcode_table[i]; } @@ -1386,7 +1386,7 @@ static BOOL shader_sm4_read_param(struct wined3d_sm4_data *priv, const DWORD **p token = *(*ptr)++; register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT; - if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table) + if (register_type >= ARRAY_SIZE(register_type_table) || register_type_table[register_type] == ~0u) { FIXME("Unhandled register type %#x.\n", register_type); diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 950c4d511c3..61337392f77 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -6049,7 +6049,7 @@ static void validate_state_table(struct StateEntry *state_table) if (i == STATE_RENDER(rs_holes[current].last)) ++current; } - for (i = 0; i < sizeof(simple_states) / sizeof(*simple_states); ++i) + for (i = 0; i < ARRAY_SIZE(simple_states); ++i) { if (!state_table[simple_states[i]].representative) ERR("State %s (%#x) should have a representative.\n", diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 40ce7b37a70..f80b8750b4f 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -237,16 +237,16 @@ static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states states->pixelShader = 1; - for (i = 0; i < sizeof(pixel_states_render) / sizeof(*pixel_states_render); ++i) + for (i = 0; i < ARRAY_SIZE(pixel_states_render); ++i) { DWORD rs = pixel_states_render[i]; states->renderState[rs >> 5] |= 1u << (rs & 0x1f); } - for (i = 0; i < sizeof(pixel_states_texture) / sizeof(*pixel_states_texture); ++i) + for (i = 0; i < ARRAY_SIZE(pixel_states_texture); ++i) texture_mask |= 1u << pixel_states_texture[i]; for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask; - for (i = 0; i < sizeof(pixel_states_sampler) / sizeof(*pixel_states_sampler); ++i) + for (i = 0; i < ARRAY_SIZE(pixel_states_sampler); ++i) sampler_mask |= 1u << pixel_states_sampler[i]; for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask; states->pixelShaderConstantsB = 0xffff; @@ -264,16 +264,16 @@ static void stateblock_savedstates_set_vertex(struct wined3d_saved_states *state states->vertexDecl = 1; states->vertexShader = 1; - for (i = 0; i < sizeof(vertex_states_render) / sizeof(*vertex_states_render); ++i) + for (i = 0; i < ARRAY_SIZE(vertex_states_render); ++i) { DWORD rs = vertex_states_render[i]; states->renderState[rs >> 5] |= 1u << (rs & 0x1f); } - for (i = 0; i < sizeof(vertex_states_texture) / sizeof(*vertex_states_texture); ++i) + for (i = 0; i < ARRAY_SIZE(vertex_states_texture); ++i) texture_mask |= 1u << vertex_states_texture[i]; for (i = 0; i < MAX_TEXTURES; ++i) states->textureState[i] = texture_mask; - for (i = 0; i < sizeof(vertex_states_sampler) / sizeof(*vertex_states_sampler); ++i) + for (i = 0; i < ARRAY_SIZE(vertex_states_sampler); ++i) sampler_mask |= 1u << vertex_states_sampler[i]; for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) states->samplerState[i] = sampler_mask; states->vertexShaderConstantsB = 0xffff; diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 134b6d204f9..bd36aa9ea11 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -1236,7 +1236,7 @@ static inline const struct d3dfmt_converter_desc *find_converter(enum wined3d_fo { unsigned int i; - for (i = 0; i < (sizeof(converters) / sizeof(*converters)); ++i) + for (i = 0; i < ARRAY_SIZE(converters); ++i) { if (converters[i].from == from && converters[i].to == to) return &converters[i]; -- 2.11.4.GIT