Pointer and reference local variables should be "const" if the corresponding object is not modified

my code looks like this:

esp_err_t iot_button_set_evt_cb(button_handle_t btn_handle, button_cb_type_t type, button_cb cb, const void* arg)
    POINT_ASSERT(TAG, btn_handle, ESP_ERR_INVALID_ARG) //no semicolon, because Macro.
	button_dev_t* btn = (button_dev_t*) btn_handle;
    if (type == BUTTON_CB_PUSH) {
        btn->tap_psh_cb.arg = arg;
        btn->tap_psh_cb.cb = cb;

you can find it there:

Sonar tells me:
Make the type of this variable a pointer-to-const. The current type of “btn” is “struct button_dev *”.
btn-> makes writes to the btn which is intended.

making btn a pointer to -const does not make sense here.

how to solve ?

Hello again @franz_at_zasso!

This looks like another potential false positive. It might be due to a parsing error (missing include file, non-standard syntax, etc.). You can see parsing errors by activating the debug log.
I didn’t succeed in reproducing the issue on my side so do you think you could create a small reproducer for it?
To generate a reproducer file:

Add the reproducer option to the scanner configuration:
sonar.cfamily.reproducer= "Full path to the button.c file"
Re-running the scanner should generate a file named sonar-cfamily.reproducer in the project folder.
Please share this file (I can send you a PM if you want to share it privately)

I’m looking forward to nail down this false positive!

Hi @franz_at_zasso
Let me know if you still experience the issue, or I can close the topic.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

@franz_at_zasso , I’m closing the topic. Feel free to open another one with additional information I requested if you are still encountering the issue.