let the text drawing path take a string it will not write to

DrawTextToScreen takes STR16, a mutable wchar_t*, for a string it only
measures and prints. Quest Debug System.cpp picks its text with a conditional:

  DrawTextToScreen( gubFact[ usLoop1 ] ? L"True" : L"False", ... );

which has type const wchar_t*. clang-cl's MSVC compatibility lets a bare
string literal decay to wchar_t*, but not a const wchar_t* expression, so it
reports

  error: no matching function for call to 'DrawTextToScreen'
  note: candidate function not viable: 1st argument ('const wchar_t *')
  would lose const qualifier

The parameter is const-correct in every function DrawTextToScreen hands the
string on to, so the change follows the string down the call chain rather
than stopping at the top:

  DrawTextToScreen, ShadowText          Utils/WordWrap.h
  WFStringPixLength                     Utils/Font Control.h
  mprintf, StringPixLength,             sgp/Font.h
  VarFindFontCenterCoordinates,
  VarFindFontRightCoordinates
  WinFontStringPixLength                sgp/WinFont.h
  gprintfdirty                          TileEngine/Render Dirty.h

The varargs members of that list copy the format string into a local buffer
before doing anything with it, and the measuring ones walk it and return a
width; none of the nine assigns through the parameter. Where StringPixLength
casts the string to UINT16* to walk it, the cast and the local now carry the
const rather than dropping it.

Callers are unaffected: every one already passes something that converts to
const CHAR16*. Both configurations build with no new diagnostics, and the
parse sweep drops from 9 error sites in 7 files to 5 in 3.

To check the claim that nothing writes through these parameters, read the
nine bodies; each is short.
This commit is contained in:
Marco Antonio J. Costa
2026-07-23 19:29:55 -03:00
committed by majcosta
parent c6a4fdb393
commit b147e47856
10 changed files with 22 additions and 21 deletions
+1 -1
View File
@@ -717,7 +717,7 @@ BOOLEAN CopyExternBackgroundRect( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 s
// to the video buffer. // to the video buffer.
// //
//***************************************************************************** //*****************************************************************************
UINT16 gprintfdirty(INT16 x, INT16 y, STR16 pFontString, ...) UINT16 gprintfdirty(INT16 x, INT16 y, const CHAR16* pFontString, ...)
{ {
va_list argptr; va_list argptr;
CHAR16 string[512]; CHAR16 string[512];
+1 -1
View File
@@ -127,7 +127,7 @@ BOOLEAN EmptyBackgroundRects( void );
// GPRINTF DIRTY STUFF // GPRINTF DIRTY STUFF
UINT16 gprintfdirty(INT16 x, INT16 y, STR16 pFontString, ...); UINT16 gprintfdirty(INT16 x, INT16 y, const CHAR16* pFontString, ...);
UINT16 gprintfinvalidate(INT16 x, INT16 y, STR16 pFontString, ...); UINT16 gprintfinvalidate(INT16 x, INT16 y, STR16 pFontString, ...);
UINT16 gprintfRestore(INT16 x, INT16 y, STR16 pFontString, ...); UINT16 gprintfRestore(INT16 x, INT16 y, STR16 pFontString, ...);
+1 -1
View File
@@ -347,7 +347,7 @@ UINT16 WFGetFontHeight( INT32 FontNum )
} }
INT16 WFStringPixLength( STR16 string,INT32 UseFont ) INT16 WFStringPixLength( const CHAR16* string,INT32 UseFont )
{ {
return( StringPixLength( string, UseFont ) ); return( StringPixLength( string, UseFont ) );
} }
+1 -1
View File
@@ -16,7 +16,7 @@ extern INT32 giCurWinFont;
// ATE: A few winfont wrappers.. // ATE: A few winfont wrappers..
UINT16 WFGetFontHeight( INT32 FontNum ); UINT16 WFGetFontHeight( INT32 FontNum );
INT16 WFStringPixLength( STR16 string,INT32 UseFont ); INT16 WFStringPixLength( const CHAR16* string,INT32 UseFont );
+2 -2
View File
@@ -497,7 +497,7 @@ UINT16 DeleteWrappedString(WRAPPED_STRING *pWrappedString)
// do you want to display it using dirty rects, TRUE or FALSE // do you want to display it using dirty rects, TRUE or FALSE
// flags for either LEFT_JUSTIFIED, CENTER_JUSTIFIED, RIGHT_JUSTIFIED // flags for either LEFT_JUSTIFIED, CENTER_JUSTIFIED, RIGHT_JUSTIFIED
BOOLEAN DrawTextToScreen(STR16 pStr, UINT16 usLocX, UINT16 usLocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 ulFlags) BOOLEAN DrawTextToScreen(const CHAR16* pStr, UINT16 usLocX, UINT16 usLocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 ulFlags)
{ {
UINT16 usPosX = 0, usPosY = 0; UINT16 usPosX = 0, usPosY = 0;
UINT16 usFontHeight=0; UINT16 usFontHeight=0;
@@ -1874,7 +1874,7 @@ INT32 GetNewTotalYPositionOfThisString( INT32 iTotalYPosition, INT32 iPageSize,
return( iNewYPosition ); return( iNewYPosition );
} }
void ShadowText(UINT32 uiDestVSurface, STR16 pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ) void ShadowText(UINT32 uiDestVSurface, const CHAR16* pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY )
{ {
UINT32 uiLength = StringPixLength( pString, iFont); UINT32 uiLength = StringPixLength( pString, iFont);
UINT16 usFontHeight = WFGetFontHeight( iFont ); UINT16 usFontHeight = WFGetFontHeight( iFont );
+2 -2
View File
@@ -50,7 +50,7 @@ void CleanOutControlCodesFromString(STR16 pSourceString, STR16 pDestString);
INT16 IanDisplayWrappedStringToPages(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT16 usPageHeight, UINT16 usTotalHeight, UINT16 usPageNumber,UINT8 ubGap, INT16 IanDisplayWrappedStringToPages(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT16 usPageHeight, UINT16 usTotalHeight, UINT16 usPageNumber,UINT8 ubGap,
INT32 iFont, UINT8 ubColor, STR16 pString, INT32 iFont, UINT8 ubColor, STR16 pString,
UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags, BOOLEAN *fOnLastPageFlag); UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags, BOOLEAN *fOnLastPageFlag);
BOOLEAN DrawTextToScreen(STR16 pStr, UINT16 LocX, UINT16 LocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 FLAGS); BOOLEAN DrawTextToScreen(const CHAR16* pStr, UINT16 LocX, UINT16 LocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 FLAGS);
UINT16 IanWrappedStringHeight(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT8 ubGap, UINT16 IanWrappedStringHeight(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT8 ubGap,
INT32 iFont, UINT8 ubColor, STR16 pString, INT32 iFont, UINT8 ubColor, STR16 pString,
UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags); UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags);
@@ -62,7 +62,7 @@ RecordPtr GetFirstRecordOnThisPage( RecordPtr RecordList, INT32 iFont, UINT16 us
FileStringPtr GetFirstStringOnThisPage( FileStringPtr RecordList, INT32 iFont, UINT16 usWidth, UINT8 ubGap, INT32 iPage, INT32 iPageSize, FileRecordWidthPtr iWidthArray ); FileStringPtr GetFirstStringOnThisPage( FileStringPtr RecordList, INT32 iFont, UINT16 usWidth, UINT8 ubGap, INT32 iPage, INT32 iPageSize, FileRecordWidthPtr iWidthArray );
// Places a shadow the width an height of the string, to PosX, posY // Places a shadow the width an height of the string, to PosX, posY
void ShadowText(UINT32 uiDestVSurface, STR16 pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ); void ShadowText(UINT32 uiDestVSurface, const CHAR16* pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY );
BOOLEAN ReduceStringLength( STR16 pString, UINT32 uiWidthToFitIn, INT32 iFont ); BOOLEAN ReduceStringLength( STR16 pString, UINT32 uiWidthToFitIn, INT32 iFont );
+7 -6
View File
@@ -584,10 +584,11 @@ INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont)
// Returns the length of a string in pixels, depending on the font given. // Returns the length of a string in pixels, depending on the font given.
// //
//***************************************************************************** //*****************************************************************************
INT16 StringPixLength(const STR16 string, INT32 UseFont) INT16 StringPixLength(const CHAR16* string, INT32 UseFont)
{ {
UINT32 Cur; UINT32 Cur;
UINT16 *curletter,transletter; const UINT16 *curletter;
UINT16 transletter;
if ( iUseWinFonts ) { if ( iUseWinFonts ) {
INT32 MapFont; INT32 MapFont;
MapFont = WinFontMap[UseFont]; MapFont = WinFontMap[UseFont];
@@ -602,7 +603,7 @@ INT16 StringPixLength(const STR16 string, INT32 UseFont)
} }
Cur=0; Cur=0;
curletter = (UINT16 *)string; curletter = (const UINT16 *)string;
while((*curletter) != L'\0') while((*curletter) != L'\0')
{ {
@@ -813,7 +814,7 @@ BOOLEAN SetFontDestBuffer(UINT32 DestBuffer, INT32 x1, INT32 y1, INT32 x2, INT32
// the parameters are identical to printf. The resulting string may be no longer // the parameters are identical to printf. The resulting string may be no longer
// than 512 word-characters. Uses monochrome font color settings // than 512 word-characters. Uses monochrome font color settings
//***************************************************************************** //*****************************************************************************
UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...) UINT32 mprintf(INT32 x, INT32 y, const CHAR16* pFontString, ...)
{ {
INT32 destx, desty; INT32 destx, desty;
CHAR16 *curletter, transletter; CHAR16 *curletter, transletter;
@@ -864,7 +865,7 @@ UINT8 *pDestBuf;
return(0); return(0);
} }
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ) void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... )
{ {
CHAR16 string[512]; CHAR16 string[512];
va_list argptr; va_list argptr;
@@ -876,7 +877,7 @@ void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 s
FindFontRightCoordinates( sLeft, sTop, sWidth, sHeight, string, iFontIndex, psNewX, psNewY ); FindFontRightCoordinates( sLeft, sTop, sWidth, sHeight, string, iFontIndex, psNewX, psNewY );
} }
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ) void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... )
{ {
CHAR16 string[512]; CHAR16 string[512];
va_list argptr; va_list argptr;
+4 -4
View File
@@ -104,7 +104,7 @@ extern BOOLEAN IsFontLoaded(INT32 iFont);
extern HVOBJECT GetFontObject(INT32 iFont); extern HVOBJECT GetFontObject(INT32 iFont);
extern UINT32 gprintf(INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 gprintf(INT32 x, INT32 y, const STR16 pFontString, ...);
extern UINT32 gprintfDirty(INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 gprintfDirty(INT32 x, INT32 y, const STR16 pFontString, ...);
extern UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 mprintf(INT32 x, INT32 y, const CHAR16* pFontString, ...);
extern UINT32 gprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 gprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...);
extern UINT32 mprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 mprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...);
@@ -132,15 +132,15 @@ extern UINT32 GetWidth(HVOBJECT hSrcVObject, INT16 ssIndex);
extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, STR16 pFontString ); extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, STR16 pFontString );
extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, STR16 pFontString, ...); extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, STR16 pFontString, ...);
extern INT16 StringPixLength(const STR16 string,INT32 UseFont); extern INT16 StringPixLength(const CHAR16* string,INT32 UseFont);
extern INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont); extern INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont);
extern INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont); extern INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont);
extern void SaveFontSettings(void); extern void SaveFontSettings(void);
extern void RestoreFontSettings(void); extern void RestoreFontSettings(void);
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ); void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... );
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ); void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... );
void FindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, const STR16 pStr, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY ); void FindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, const STR16 pStr, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY );
+2 -2
View File
@@ -461,7 +461,7 @@ void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontS
} }
INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) INT16 WinFontStringPixLength( const CHAR16* string2, INT32 iFont )
{ {
HWINFONT *pWinFont; HWINFONT *pWinFont;
pWinFont = GetWinFont( iFont ); pWinFont = GetWinFont( iFont );
@@ -469,7 +469,7 @@ INT16 WinFontStringPixLength( STR16 string2, INT32 iFont )
if (pWinFont == NULL) return(0); if (pWinFont == NULL) return(0);
if(g_lang == i18n::Lang::zh) { if(g_lang == i18n::Lang::zh) {
wchar_t *p=string2; const wchar_t *p=string2;
UINT32 size = 0; UINT32 size = 0;
while (*p!=0) while (*p!=0)
{ {
+1 -1
View File
@@ -16,7 +16,7 @@ void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor );
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...); void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...);
INT16 WinFontStringPixLength( STR16 string, INT32 iFont ); INT16 WinFontStringPixLength( const CHAR16* string, INT32 iFont );
INT16 GetWinFontHeight( INT32 iFont ); INT16 GetWinFontHeight( INT32 iFont );
//if you cahnge this enum, you must change FontInfo struct in WinFont.cpp too. //if you cahnge this enum, you must change FontInfo struct in WinFont.cpp too.