I was thinking about doing it like this:
443 size = FIELD_OFFSET(ACTCTXA, wProcessorArchitecture); 444 if (actctx->dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID) 445 size = max(size, FIELD_OFFSET(ACTCTXA, wLangId)); 446 if (actctx->dwFlags & ACTCTX_FLAG_LANGID_VALID) 447 size = max(size, FIELD_OFFSET(ACTCTXA, lpAssemblyDirectory)); 448 if (actctx->dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) 449 size = max(size, FIELD_OFFSET(ACTCTXA, lpResourceName)); 450 if (actctx->dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID) 451 size = max(size, FIELD_OFFSET(ACTCTXA, lpApplicationName)); 452 if (actctx->dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) 453 size = max(size, FIELD_OFFSET(ACTCTXA, hModule)); 454 if (actctx->dwFlags & ACTCTX_FLAG_HMODULE_VALID) 455 size = sizeof(ACTCTXA); 456 if (actctx->cbSize < size) 457 { 458 SetLastError(ERROR_INVALID_PARAMETER); 459 return INVALID_HANDLE_VALUE; 460 }
Then duplicating exactly the same check in CreateActCtxW(), structure layout is the same. This way we won't need six size checks and six jumps, times two.
Yes, this avoids duplicate size checks, however it introduces duplicate dwFlags checks and makes things even worse with an influx of max() invocations that lead to actually duplicating of the size checks. I don't like what I see in the generated assebler. Why do you think that's a better approach?