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

C++アウトラインでclass x final:base{}と:がfinalにくっついているとクラス名がfinalになる不具合の修正 #1612

Conversation

usagisita
Copy link
Contributor

@usagisita usagisita commented Mar 28, 2021

PR の目的

C++アウトラインで、class名がfinalになってしまう不具合を修正します。

カテゴリ

  • 不具合修正

PR の背景

PR のメリット

アウトライン解析が若干正確になります。

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

特にありません。

仕様・動作説明

class MY_MACRO class_name{};

C++アウトライン解析では、クラス名がMY_MACROではなく class_nameになるように後ろの単語が優先されるようです。
その際にfinalキーワードは無視されるようになっています。
しかしサクラエディタの実装では単語単位の解析に:を含んでいてfinalの直後にある:がスペースを挟んでいるかで、実行されるコードが異なります。
そこで、スペース側ではfinalの考慮がされていましたが、くっついている側の処理では抜けていました。

なお無名クラスかのチェックがあり、言語が日本語の時、クラス名が漢字で無名だと、無名クラスと認識されてfinalがクラス名にされてしまう制限があります。

class 無名 final : public base{};

本当の無名クラスをfinal指定することは、言語仕様上できません。

PR の影響範囲

C++アウトライン解析の該当部分のみです。

テスト内容

テスト1

手順

class c1 final {};
class c2 final:base{}; //
class c3 final :base{};
class c4 final: base{}; //
class c5 final : base{};

class c6 final {};
class c7 final:public base{}; //
class c8 final :public base{};
class c9 final: public base{}; //
class c10 final : public base{};

// こちらはクラス名がfinal(後方互換、文脈依存キーワード)
class final{};
class final: public base{};
class final : public base{};

このソースコードをサクラエディタに貼り付けて、C++のアウトライン解析を実行します。
PRの修正前は「c2, c4, c7, c9」のクラス名がfinalになってしまっています。
PRの修正適用後は正しく表示されるようになります。

関連 issue, PR

参考資料

@sonarcloud
Copy link

sonarcloud bot commented Mar 28, 2021

Kudos, SonarCloud Quality Gate passed!

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

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@AppVeyorBot
Copy link

Build sakura 1.0.3624 completed (commit 64580ad4f4 by @usagisita)

Copy link
Contributor

@berryzplus berryzplus left a comment

Choose a reason for hiding this comment

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

問題なさそうに思います。

wcscmp(a,b)はa,bにszを想定する関数で、
a,bのいずれかにNUL終端が現れた時点で評価を終了するので、
セキュリティ問題は発生しない認識です。
(というか、wcsncmpにすると意味が変わる・・・)

@usagisita
Copy link
Contributor Author

レビューありがとうございました。
マージします。

@usagisita usagisita merged commit d50a6c5 into sakura-editor:master Mar 29, 2021
@usagisita usagisita deleted the feature/fix_cpp_outline_final_class_name branch March 29, 2021 13:37
@beru beru added the 🐛bug🦋 ■バグ修正(Something isn't working) label Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug🦋 ■バグ修正(Something isn't working)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants