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

[Coverity] Fix coverity issues #2526

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

djeong20
Copy link
Contributor

This PR resolves coverity issues of overflow, use of auto that causes a copy, missing lock and thread lock.

Self-evaluation:

  1. Build test: [X]Passed [ ]Failed [ ]Skipped
  2. Run test: [X]Passed [ ]Failed [ ]Skipped

@taos-ci
Copy link
Collaborator

taos-ci commented Mar 29, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2526. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@djeong20, 💯 All CI checkers are successfully verified. Thanks.

num_observed++;
if (num_observed == iteration.batch()) {
notify_lock_guard.unlock();
Copy link
Member

@myungjoo myungjoo Mar 29, 2024

Choose a reason for hiding this comment

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

Why unlock here? It seems that num_observed may experience synchronization error.

After this patch.

Thread 1         Thread 2
LINE 198 (after ++, num_observed=iteration-batch)
LINE 200
LINE 201
                        LINE 198 (after ++, num_observed = i-b + 1)
                        LINE 205
LINE 202
LINE 203 (num_objserved = 0)
LINE 205

Before this patch, it becomes num_observed = 1
You can miss num_observed counting after this commit.

Copy link
Member

Choose a reason for hiding this comment

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

If markFilled() cannot affect num_observed or iteration.batch() and num_observed cannot affect markFilled(), you can do num_observed = 0; before unlock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. how about adding a cv?

std::unique_lock notify_lock_guard(notify_mutex);
notify_emptied_num_obs_cv.wait(
  notify_mutex, [this] { return num_observed != iteration.batch(); });
num_observed++;
if (num_observed == iteration.batch()) {
  notify_lock_guard.unlock();
  iq->markFilled(this);
  notify_lock_guard.lock();
  num_observed = 0;
  notify_num_emptied_cv.notify_all();
}

Copy link
Member

@myungjoo myungjoo Mar 29, 2024

Choose a reason for hiding this comment

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

It's over-engineering. You don't need that much complexity. (is CV really required? can you do it only with mutex?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha. Thank you for your guidance!

This PR resolves coverity issues of overflow, use of auto that causes a copy, missing lock and thread lock.

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
Copy link
Member

@DonghakPark DonghakPark left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@djeong20, 💯 All CI checkers are successfully verified. Thanks.

Copy link
Member

@SeoHyungjun SeoHyungjun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@skykongkong8 skykongkong8 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@jijoongmoon jijoongmoon left a comment

Choose a reason for hiding this comment

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

LGTM

@jijoongmoon jijoongmoon merged commit c225bdd into nnstreamer:main Apr 1, 2024
32 checks passed
@djeong20 djeong20 deleted the fix/coverity/032924 branch July 26, 2024 08:45
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.

7 participants