fix: use the standard va_list macros where applicable.

This commit is contained in:
Rainer Kottenhoff 2026-05-02 12:05:10 +02:00
parent ec1fdd2219
commit 90bf370ece
2 changed files with 17 additions and 8 deletions

View File

@ -475,12 +475,13 @@ LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...)
msgBox.uType = uType;
msgBox.lpstrMessage = AllocMem((COUNTOF(wchMessage)+1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
const PUINT_PTR argp = (PUINT_PTR)& uidMsg + 1;
if (argp && *argp) {
StringCchVPrintfW(msgBox.lpstrMessage, COUNTOF(wchMessage), wchMessage, (LPVOID)argp);
} else {
StringCchCopy(msgBox.lpstrMessage, COUNTOF(wchMessage), wchMessage);
}
// Use va_list (not the &uidMsg+1 stack-walk hack): on Windows ARM64 the first 8
// varargs are in registers X0X7, not at &uidMsg+1, so the old code read garbage and
// typically fell through to the no-args branch — leaving literal "%s" in the message.
va_list args;
va_start(args, uidMsg);
StringCchVPrintfW(msgBox.lpstrMessage, COUNTOF(wchMessage), wchMessage, args);
va_end(args);
bool bLastError = false;
switch (uidMsg) {

View File

@ -644,7 +644,12 @@ int FormatLngStringW(LPWSTR lpOutput, int nOutput, UINT uIdFormat, ...)
WCHAR* const pBuffer = AllocMem(sizeof(WCHAR) * nOutput, HEAP_ZERO_MEMORY);
if (pBuffer) {
if (LoadLngStringW(uIdFormat, pBuffer, nOutput)) {
StringCchVPrintfW(lpOutput, nOutput, pBuffer, (LPVOID)((PUINT_PTR)& uIdFormat + 1));
// va_list, not &uIdFormat+1 — the latter walks the stack and breaks on ARM64
// where the first 8 varargs are in X0X7 registers.
va_list args;
va_start(args, uIdFormat);
StringCchVPrintfW(lpOutput, nOutput, pBuffer, args);
va_end(args);
}
FreeMem(pBuffer);
return (int)StringCchLen(lpOutput, nOutput);
@ -661,7 +666,10 @@ int FormatLngStringA(LPSTR lpOutput, int nOutput, UINT uIdFormat, ...)
CHAR* const pBuffer = AllocMem(sizeof(CHAR) * nOutput, HEAP_ZERO_MEMORY);
if (pBuffer) {
if (LoadLngStringA(uIdFormat, pBuffer, nOutput)) {
StringCchVPrintfA(lpOutput, nOutput, pBuffer, (LPVOID)((PUINT_PTR)& uIdFormat + 1));
va_list args;
va_start(args, uIdFormat);
StringCchVPrintfA(lpOutput, nOutput, pBuffer, args);
va_end(args);
}
FreeMem(pBuffer);
return (int)StringCchLenA(lpOutput, nOutput);