notepad-plus-plus / notepad-plus-plus/notepad-plus-plus

[BUG] The ShortcutKey pointer in a FuncItem should be a const pointer

Open
#16,255 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
29.4k
Forks
5.4k
PR merge metrics
No merged PRs in 30d

Description

Is there an existing issue for this?
  • I have searched the existing issues
Description of the Issue

A FuncItem is defined as this in PluginInterface.h :

struct FuncItem
{
	TCHAR _itemName[menuItemSize] = { '\0' };
	PFUNCPLUGINCMD _pFunc = nullptr;
	int _cmdID = 0;
	bool _init2Check = false;
	ShortcutKey *_pShKey = nullptr;
};

As you don't write to the shortcut keys they should be const pointers. This makes it a little tricky to write const correct code where shortcut keys are configurable by the user.

Steps To Reproduce
  1. Using visual c++ 20, write something like this:
ShortcutKey const k1 = { .isAlt_ = true, .key_ = 'Z' };
...
FuncItem item { ._pShKey = &k1; }
Current Behavior

Sample code doesn't compile

Expected Behavior

Sample code does compile

Debug Information
Notepad++ v8.7.5   (64-bit)
Build time : Dec 21 2024 - 05:13:03
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : 
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
DirectWrite : OFF
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : OFF
OS Name : Windows 11 Pro (64-bit)
OS Version : 24H2
OS Build : 26100.3194
Current ANSI codepage : 1252
Plugins : 
    ComparePlugin (2.0.2)
    DialogueDemo (1.0.0.1)
    HexEditor (0.9.12)
    JSLintNpp (0.8.2.118)
    Linter (0.1)
    Linter++ (0.1)
    mimeTools (3.1)
    NppConverter (4.6)
    NppEditorConfig (0.4)
    NppExport (0.4)
    NppFTP (0.29.9)
    NPPJSONViewer (1.40)
    NppXmlTreeviewPlugin (2)
    Papyrus (0.4.0.27)
    PreviewHTML (1.3.2)
    PythonScript (2)
    SessionMgr (1.4.4)
    XMLTools (3.1.1.13)
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read PluginInterface.h and inspect FuncItem's _pShKey declaration alongside ShortcutKey. Verify the const-correct declaration with the Visual C++ 20 sample from the issue; it is done when that sample compiles without allowing shortcut-key mutation through FuncItem.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.