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

Fix Coverity uninitialized pointer field Thread.h #11273

Merged
merged 1 commit into from
Aug 22, 2019

Conversation

Tharazi97
Copy link
Contributor

@Tharazi97 Tharazi97 commented Aug 21, 2019

Description

Changed _obj_mem to be initialized with creating new thread.

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@jamesbeyond @maciejbocianski

Release Notes

@ciarmcom ciarmcom requested review from a team August 21, 2019 09:00
@ciarmcom
Copy link
Member

@Tharazi97, thank you for your changes.
@ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

rtos/Thread.h Outdated
@@ -540,7 +540,7 @@ class Thread : private mbed::NonCopyable<Thread> {
bool _dynamic_stack;
Semaphore _join_sem;
mutable Mutex _mutex;
mbed_rtos_storage_thread_t _obj_mem;
mbed_rtos_storage_thread_t _obj_mem = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current init is in start() method - it sets this to 0:

memset(&_obj_mem, 0, sizeof(_obj_mem));

Assuming based on how it is initialized (POD type), this could be handled in the constructor as the rest of members - to be consistent however this is valid now as it is.

Copy link
Contributor

@kjbracey kjbracey Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the existing constructor method and its in-body init - now we're C++11 you could use proper constructor delegation, and the final most-flexible constructor could do everything via its member-initializer list.

I'd also prefer if everything was consistent - all defaults in body of constructor, all defaults in member-initializer-list, or all defaults as default-member initializers.

So make it a memset in constructor, or do a more wide-ranging refactor/tidy including real constructor delegation.

@kjbracey
Copy link
Contributor

I guess this is warning about get_state accessing _obj_mem.state? It can't figure out that _tid only becomes non-NULL after a memset of _obj_mem? Otherwise, not sure why it would think this is a problem.

I think this is probably fine, but you should net off the size increase a bit by removing the memset from Thread::start.

@Tharazi97
Copy link
Contributor Author

Yes I think it is warning caused by get_state(). In constructor _tid gets asigned to 0. Maybe it should have become nullptr in constructor'' and memset'' of _obj_mem should be left in start?

@kjbracey
Copy link
Contributor

Yes I think it is warning caused by get_state(). In constructor _tid gets asigned to 0. Maybe it should have become nullptr in constructor'' and memset'' of _obj_mem should be left in start?

You could certainly set _tid to nullptr as a style change, but that won't be impacting Coverity's complaint (99% certainty).

Changed _obj_mem to be initialized with constructor of new thread.
@Tharazi97
Copy link
Contributor Author

@kjbracey-arm you were right. I've moved memset to the constructor.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2019

started CI

@adbridge
Copy link
Contributor

restarted

@mbed-ci
Copy link

mbed-ci commented Aug 21, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@Tharazi97
Copy link
Contributor Author

CI fail seems not related.
test case: 'tests-mbed_hal-reset_reason' ..................................................... FAIL in 48.35 sec

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 22, 2019

Test restarted

@0xc0170 0xc0170 merged commit 0c18a77 into ARMmbed:master Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants