Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cppcheck: remove statics in test mqbsl_readwriteondisklog.t.cpp #72

Open
1 task done
678098 opened this issue Aug 7, 2023 · 2 comments
Open
1 task done

Cppcheck: remove statics in test mqbsl_readwriteondisklog.t.cpp #72

678098 opened this issue Aug 7, 2023 · 2 comments
Assignees
Labels
A-Testing Area: Testing enhancement New feature or request good first issue Good for newcomers

Comments

@678098
Copy link
Collaborator

678098 commented Aug 7, 2023

Is there an existing proposal for this?

  • 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:

bdlbb::PooledBlobBufferFactory bufferFactory(k_LONG_ENTRY_LENGTH * 2,
s_allocator_p);
bdlbb::PooledBlobBufferFactory miniBufferFactory(k_ENTRY_LENGTH,
s_allocator_p);
g_bufferFactory_p = &bufferFactory;
g_miniBufferFactory_p = &miniBufferFactory;

And make it a field of the Tester class, which is constructed locally for each test.

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 678098 added enhancement New feature or request good first issue Good for newcomers A-Testing Area: Testing labels Aug 7, 2023
@qmarsun
Copy link

qmarsun commented Sep 7, 2023

image
image

I assume those are the required to fix these global variables

@678098
Copy link
Collaborator Author

678098 commented Sep 7, 2023

@qmarsun22 yes, it's correct

@syuzvinsky syuzvinsky self-assigned this Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Testing Area: Testing enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants