blazingmq icon indicating copy to clipboard operation
blazingmq copied to clipboard

Cppcheck: remove statics in test `mqbsl_readwriteondisklog.t.cpp`

Open 678098 opened this issue 2 years ago • 2 comments

Is there an existing proposal for this?

  • [X] I have searched the existing proposals

Is your feature request related to a problem?

cppcheck output:

src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:945:9: error: Non-local variable 'g_bufferFactory_p' will use pointer to local variable 'bufferFactory'. [danglingLifetime]
        g_bufferFactory_p     = &bufferFactory;
        ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:945:33: note: Address of variable taken here.
        g_bufferFactory_p     = &bufferFactory;
                                ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:941:40: note: Variable created here.
        bdlbb::PooledBlobBufferFactory bufferFactory(k_LONG_ENTRY_LENGTH * 2,
                                       ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:945:9: note: Non-local variable 'g_bufferFactory_p' will use pointer to local variable 'bufferFactory'.
        g_bufferFactory_p     = &bufferFactory;
        ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:946:9: error: Non-local variable 'g_miniBufferFactory_p' will use pointer to local variable 'miniBufferFactory'. [danglingLifetime]
        g_miniBufferFactory_p = &miniBufferFactory;
        ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:946:33: note: Address of variable taken here.
        g_miniBufferFactory_p = &miniBufferFactory;
                                ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:943:40: note: Variable created here.
        bdlbb::PooledBlobBufferFactory miniBufferFactory(k_ENTRY_LENGTH,
                                       ^
src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp:946:9: note: Non-local variable 'g_miniBufferFactory_p' will use pointer to local variable 'miniBufferFactory'.
        g_miniBufferFactory_p = &miniBufferFactory;

Describe the solution you'd like

Will be nice to remove global objects construction from here: https://github.com/bloomberg/blazingmq/blob/ca6491f69eea8d91733fa36ef3e82c4facc734fc/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp#L941-L946

And make it a field of the Tester class, which is constructed locally for each test. https://github.com/bloomberg/blazingmq/blob/ca6491f69eea8d91733fa36ef3e82c4facc734fc/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp#L124

Current implementation has a good point - it builds these global objects once and saves some processing time on rebuilding it. But this also might be a problem, because it's a shared state among tests.

Alternatives you considered

No response

678098 avatar Aug 07 '23 10:08 678098

image image

I assume those are the required to fix these global variables

qmarsun avatar Sep 07 '23 08:09 qmarsun

@qmarsun22 yes, it's correct

678098 avatar Sep 07 '23 08:09 678098