Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQubeの静的解析で検出されたFileNameSepExtのバグを修正する(その2) #1797

Conversation

berryzplus
Copy link
Contributor

PR の目的

SonarCloudにバグだと言われているコードを修正し、見た目の品質を上げます。

カテゴリ

  • リファクタリング

※検知されたのは「nullチェック漏れによるクラッシュの可能性」ですが、
 実態として実害はないと考えられるためリファクタリングとします。

PR の背景

SonarCloudにより以下の不具合が検出されています。
https://sonarcloud.io/project/issues?id=sakura-editor_sakura&issues=AXhxfE2dTNlLrH0R7vj9&open=AXhxfE2dTNlLrH0R7vj9

utif/file.cpp 内のローカル関数 FileNameSepExt の第一引数 filenullptr が渡された場合の考慮がないよ(≒渡ってきたら落ちるよ)という指摘です。

PR のメリット

  • SonarCloudにバグと検出される残念なコードが1つ消えます。

PR のデメリット (トレードオフとかあれば)

仕様・動作説明

アプリの仕様・機能に変更はありません。

  • FileNameSepExt  = 問題が検出された関数です。
    • シグニチャを変更して filenullptr を渡せないようにします。
    • シグニチャを変更してout引数のバッファサイズを考慮しなくて良いようにします。
  • FileMatchScoreSepExt  = FileNameSepExtの呼出元関数
    • シグニチャを変更して file1file2nullptr を渡せないようにします。
    • バッファ変数の定義型をWCHAR[260] から std::wstring に変更します。

PR の影響範囲

Diffダイアログに表示するファイル名比較に使われる関数です。

テスト内容

このPRは、修正部分のテストを含んでいます。

テスト1

手順

関連 issue, PR

参考資料

@AppVeyorBot
Copy link

MinGWは文字列のエンコーディングをShift-JISと仮定するため、サロゲート文字をベタ書きできなかった。
@AppVeyorBot
Copy link

@sonarcloud
Copy link

sonarcloud bot commented Feb 12, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@berryzplus berryzplus marked this pull request as ready for review February 12, 2022 11:57
Copy link
Member

@kengoide kengoide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

問題なさそうに見えます。

@berryzplus
Copy link
Contributor Author

レビューありがとうございます。マージしてしまいます。
何か不都合あれば別PRで対応していきたいと思います。

@berryzplus berryzplus merged commit 594c4b0 into sakura-editor:master Feb 12, 2022
@berryzplus berryzplus deleted the feature/refactoring_of_FileMatchScore branch February 12, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants