CRuler::DrawRulerBg において TextOutW を呼び出す際に第5引数の型 (int) にキャストする記述を追加して警告回避 #1559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR の目的
x64 ビルドで警告が出る数を減らす為の変更です。
カテゴリ
PR の背景
x64 のビルドで警告が大量に出る事が #430 で話されています。
PR のメリット
sakura
プロジェクトの x64 Debug ビルド時の警告の数が 601 から 600 になり、1個減ります。x64 Release ビルド時の警告の数が 566 から 565 になり、1個減ります。
Win32 Debug と Win32 Release ビルド時の警告の数は 0 のままです。
(変更前のコミットは 32cdaf0)
PR のデメリット (トレードオフとかあれば)
キャストの記述の分だけコードの情報量が増える。
仕様・動作説明
呼び出すWindowsAPIの関数
TextOutW
の第5引数の型はint
で第4引数に渡した文字列バッファの長さを指定するとの事です。https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-textoutw
長さの定義については下記に記載されていますが、-1 を指定する事で呼び出し先の関数でNULL終端文字列の長さを調べてくれるお手軽仕様です。なので長さのパラメータなのに符号付の型になっているようです。
https://docs.microsoft.com/en-us/windows/win32/gdi/specifying-length-of-text-output-string
という事は
wcslen( szColumn )
の記述にキャストを入れるのではなくて -1 に置き換えてしまうのもありかもしれないですね。PR の影響範囲
今までは暗黙的に
int
にキャストしていたものを明示的にキャストする記述にしましたが、動作への影響はないと思います。https://docs.microsoft.com/en-us/cpp/cpp/type-conversions-and-type-safety-modern-cpp?view=msvc-160#narrowing-conversions-coercion
によると
という事で、今回はキャスト前の値がキャスト先の型の範囲内に収まる事が明確なので明示的なキャストで何の問題もないと考えます。
テスト内容
テスト1
関連 issue, PR
#430 #1541
参考資料