Skip to content

NULLマクロの再定義をやめる#2104

Merged
berryzplus merged 4 commits into
sakura-editor:masterfrom
berryzplus:feature/revert_null_redefine
Jul 21, 2025
Merged

NULLマクロの再定義をやめる#2104
berryzplus merged 4 commits into
sakura-editor:masterfrom
berryzplus:feature/revert_null_redefine

Conversation

@berryzplus

@berryzplus berryzplus commented Jun 29, 2025

Copy link
Copy Markdown
Contributor

PR対象

  • アプリ(サクラエディタ本体)
  • テストコード

カテゴリ

  • 削除

PR の背景

このプロジェクトでは NULLマクロを nullptr に再定義することで、
ポインタに NULL を代入するコードの警告を抑制しています。

しかし、NULLが本来の目的、無効値として使われる状況では数値型引数に NULL を指定したりするので NULL を nullptr に置換する対応では都合がよくありません。

いまのところ、 gdiplus.h をインクルードするとコンパイルエラーになることが分かっています。

仕様・動作説明

NULLの再定義をやめます。

PR の影響範囲

プログラム全域に影響します。

数値型引数に NULL を指定できるようになります。
ポインタ型引数に NULL を指定すると警告が出るようになります。
数値型変数に NULL を代入できるようになります。
ポインタ型変数に NULL を代入するコードで警告が出るようになります。

機能上の実害はないと考えられます。

テスト内容

ビルドできること

NULLの再定義をやめたことで発生する大量の警告は一旦放置します。

関連 issue, PR

参考資料

@m-tmatma

Copy link
Copy Markdown
Member

NULL を使い続ける個所と nullptr を使う個所の違いは何ですか?

@berryzplus

Copy link
Copy Markdown
Contributor Author

NULL を使い続ける個所と nullptr を使う個所の違いは何ですか?

数値に対してはNULLのままでよいです。
数値以外、ポインタやハンドルに対しては nullptr に変えていきます。

@berryzplus berryzplus requested a review from Copilot July 3, 2025 01:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR stops redefining the NULL macro as nullptr, reverting to the standard definition and updating code to use nullptr explicitly for pointer operations.

  • Removed custom #define NULL nullptr in StdAfx.h
  • Replaced NULL with nullptr in pointer assignments/comparisons
  • Updated unit tests to assign and compare using nullptr

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/unittests/test-cnative.cpp Removed local NULL macro hack and updated pointer tests to nullptr
sakura_core/env/CShareData.cpp Swapped all NULL pointer initializations and checks to nullptr
sakura_core/StdAfx.h Deleted custom redefinition of NULL
Comments suppressed due to low confidence (2)

tests/unittests/test-cnative.cpp:255

  • [nitpick] Replace NULL with nullptr in the assertion to keep pointer comparisons consistent after removing the NULL macro redefinition.
	EXPECT_EQ(NULL, value.GetStringPtr());

tests/unittests/test-cnative.cpp:267

  • [nitpick] Use nullptr instead of NULL here for consistency in pointer assertions.
	ASSERT_EQ(NULL, value.GetStringPtr());


// 未確保状態からの書式化をテストする
value = NULL; //テスト前の初期値(未確保
value = nullptr; //テスト前の初期値(未確保

Copilot AI Jul 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The comment is missing a closing parenthesis—consider changing to // テスト前の初期値 (未確保).

Copilot uses AI. Check for mistakes.

@berryzplus berryzplus Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

コメントに対する指摘なのでスルーします。
(修正しても振る舞いに影響がないため。)

{
std::wstring longText( 2048, L'=' );
value = NULL; //テスト前の初期値(未確保
value = nullptr; //テスト前の初期値(未確保

Copilot AI Jul 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Add the missing closing parenthesis in the comment: // テスト前の初期値 (未確保).

Suggested change
value = nullptr; //テスト前の初期値(未確保
value = nullptr; //テスト前の初期値(未確保)

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

コメントに対する指摘なのでスルーします。
(修正しても振る舞いに影響がないため。)

@berryzplus

Copy link
Copy Markdown
Contributor Author

#2110 のマージによりコンフリクト発生していたので master をマージしました。

@berryzplus

Copy link
Copy Markdown
Contributor Author

SonarQubeのNew Issue 1件は元からの問題なのでスルーしてください。

@berryzplus berryzplus requested a review from m-tmatma July 13, 2025 06:55
@sonarqubecloud

Copy link
Copy Markdown

@berryzplus berryzplus merged commit 58ca1ee into sakura-editor:master Jul 21, 2025
15 checks passed
@berryzplus berryzplus deleted the feature/revert_null_redefine branch July 21, 2025 03:53
@beru beru added the refactoring リファクタリング 【ChangeLog除外】 label Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring リファクタリング 【ChangeLog除外】

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants