Std::vector initialization problem (cpp:S5523)

Hello,

I was not lucky trying to solve the code smell. Here is a simplified version of the code, which triggers rule cpp:S5523 :

    static int test_function(void) {
        std::vector<uint8_t> data_1 = { 0 };
        std::vector<uint8_t> data_2 = {};
        std::vector<uint8_t> data_3{ 1 };

        int vector_size = 0;
        vector_size = data_1.size();
        vector_size = data_2.size();
        vector_size = data_3.size();

        return vector_size;
    }

For data_1, data_3 declared & initialized vector data.size() method returns=1. How can it be that vector is initialized with size=1 (it appears to me), yet the issue persists. Could you suggest something? Could this be a false positive?

In addition to this, I have tried enabling rule cpp:S2260 as suggested in troubleshooting section . This hasn’t changed anything. Same error is reported.

Moreover, I have generated sonar-cfamily-reproducer.zip file & could share in private for analysis.

Thank you

Hi @Ovidijus,

I sent you a PM to upload the reproducer.

Thanks,

Hi @Ovidijus,

I wasn’t able to reproduce the issue. S5523 isn’t raised at all on the shared general_commands.cpp

Also, I’m a bit confused because you shared the SonarQube reproducer while you referred to SonarLint documentation.

Do you face the issue on SonarQube or on SonarLint?

Thanks,

Hello,

My apologies. I thought that reproducer does act as both SonarQube and SonarLint. But I guess it only replicates SonarLint?

More details about the situation: SonarLint does not detect this issue. Only in the SonarQube server anlysis I am able to see this issue.

What could you suggest?

Thank you

Hello,

Sorry to ping you, but I would like to know, how should I proceed further?

Thank you.

if you reproduce the issue in SonarLint you should share the SonarLint reproducer.

if you reproduce the issue in SonarQube you should share the SonarQube reproducer.

The reproducer you shared doesn’t reproduce the issue. Are you still facing the issue? If yes, you can either mark it as false-positive or update your SonarQube to the latest version and see if it is fixed there.

Thanks,

Hello,

We are still facing the issue but decided to mark it as false positive.

Thanks for the help.

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