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: Convert C-Style Casts to C++-Style Type Casts #36416

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abd-770
Copy link
Contributor

@abd-770 abd-770 commented Sep 22, 2024

Issue:
#35900

Description:
This pull request replaces the instances of C-style casting in the codebase with C++ style type casting (static_cast, const_cast, and reinterpret_cast). This change is aimed at:

  1. Vulnerability Fix: Fixes the casting vulnerability from the static scan.
  2. Type Safety: C++-style casts are more explicit and specific than C-style casts
  3. Readability: conveys explicitly what kind of cast is being performed
  4. Adheres to the ES.49 C++ Core Guidelines

@sre-ci-robot sre-ci-robot added the do-not-merge/work-in-progress Don't merge even CI passed. label Sep 22, 2024
@sre-ci-robot sre-ci-robot added the size/L Denotes a PR that changes 100-499 lines. label Sep 22, 2024
Copy link
Contributor

mergify bot commented Sep 22, 2024

@abd-770 Thanks for your contribution. Please submit with DCO, see the contributing guide https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md#developer-certificate-of-origin-dco.

Copy link
Contributor

mergify bot commented Sep 22, 2024

@abd-770

Invalid PR Title Format Detected

Your PR submission does not adhere to our required standards. To ensure clarity and consistency, please meet the following criteria:

  1. Title Format: The PR title must begin with one of these prefixes:
  • feat: for introducing a new feature.
  • fix: for bug fixes.
  • enhance: for improvements to existing functionality.
  • test: for add tests to existing functionality.
  • doc: for modifying documentation.
  • auto: for the pull request from bot.
  1. Description Requirement: The PR must include a non-empty description, detailing the changes and their impact.

Required Title Structure:

[Type]: [Description of the PR]

Where Type is one of feat, fix, enhance, test or doc.

Example:

enhance: improve search performance significantly 

Please review and update your PR to comply with these guidelines.

@mergify mergify bot added needs-dco DCO is missing in this pull request. do-not-merge/invalid-pr-format labels Sep 22, 2024
Copy link

codecov bot commented Sep 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.97%. Comparing base (a5e0a56) to head (3806754).
Report is 212 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #36416      +/-   ##
==========================================
+ Coverage   81.05%   82.97%   +1.91%     
==========================================
  Files        1370     1081     -289     
  Lines      191486   165618   -25868     
==========================================
- Hits       155215   137421   -17794     
+ Misses      30788    22718    -8070     
+ Partials     5483     5479       -4     
Components Coverage Δ
Client 73.67% <ø> (ø)
Core ∅ <ø> (∅)
Go 83.23% <ø> (-0.01%) ⬇️

see 314 files with indirect coverage changes

@alexanderguzhva
Copy link
Contributor

to @abd-770 and whoever reviews these changes.

These automated changes need to be reviewed VERY CAREFULLY and altered manually.
For example, I see

    std::vector<uint8_t> vals;
    auto execute_sub_batch = [](Index* index_ptr,
                                const std::vector<uint8_t>& vals) {
        TermIndexFunc<bool> func;

        return std::move(func(index_ptr, vals.size(), (bool*)vals.data()));
    };

    auto res = ProcessIndexChunks<bool>(execute_sub_batch, vals);

got changed into

    std::vector<uint8_t> vals;
    auto execute_sub_batch = [](Index* index_ptr,
                                const std::vector<uint8_t>& vals) {
        TermIndexFunc<bool> func;

        return std::move(func(index_ptr, vals.size(), 
                      const_cast<bool*>(static_cast<const bool*>(
                          static_cast<const void*>(vals.data())
                      ))));
    };

    auto res = ProcessIndexChunks<bool>(execute_sub_batch, vals);

while at a first glance the problem may be fixed by changing const std::vector<uint8_t>& vals to std::vector<uint8_t>& vals

@abd-770 abd-770 changed the title Convert C-Style Casts to C++-Style Type Casts. (DO NOT MERGE) fix: Convert C-Style Casts to C++-Style Type Casts (DO NOT MERGE) Sep 24, 2024
@mergify mergify bot added kind/bug Issues or changes related a bug and removed do-not-merge/invalid-pr-format labels Sep 24, 2024
@abd-770 abd-770 force-pushed the forkedMilvus-fixCast branch from db8faa5 to 7a38102 Compare September 24, 2024 12:06
@mergify mergify bot added dco-passed DCO check passed. and removed needs-dco DCO is missing in this pull request. labels Sep 24, 2024
@abd-770 abd-770 marked this pull request as ready for review September 25, 2024 04:05
@sre-ci-robot sre-ci-robot removed the do-not-merge/work-in-progress Don't merge even CI passed. label Sep 25, 2024
Copy link
Contributor

mergify bot commented Sep 25, 2024

@abd-770 go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Sep 25, 2024

@abd-770 E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

@abd-770
Copy link
Contributor Author

abd-770 commented Sep 25, 2024

rerun go-sdk

@abd-770
Copy link
Contributor Author

abd-770 commented Sep 25, 2024

/run-cpu-e2e

Copy link
Contributor

mergify bot commented Sep 25, 2024

@abd-770 E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Copy link
Contributor

mergify bot commented Sep 25, 2024

@abd-770 go-sdk check failed, comment rerun go-sdk can trigger the job again.

@abd-770
Copy link
Contributor Author

abd-770 commented Sep 27, 2024

@alexanderguzhva can you tag someone from the community to review this pr. Thanks

@abd-770 abd-770 changed the title fix: Convert C-Style Casts to C++-Style Type Casts (DO NOT MERGE) fix: Convert C-Style Casts to C++-Style Type Casts Sep 27, 2024
Copy link
Contributor

mergify bot commented Sep 27, 2024

@abd-770 E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Copy link
Contributor

mergify bot commented Sep 27, 2024

@abd-770 go-sdk check failed, comment rerun go-sdk can trigger the job again.

@alexanderguzhva
Copy link
Contributor

@abd-770 would it be possible to run clang-format in order to fix the formatting? thanks

@abd-770 abd-770 force-pushed the forkedMilvus-fixCast branch from 7a38102 to 1d8b9d4 Compare September 30, 2024 08:46

auto status = CStatus();
status.error_code = milvus::Success;
status.error_msg = "";
auto group = (CPlaceholderGroup)res.release();
auto group = static_cast<CPlaceholderGroup>(res.release());
Copy link
Contributor

Choose a reason for hiding this comment

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

same, is it really CPlaceholderGroup and not CPlaceholderGroup*?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.
CPlaceholderGroup is defined as void *.
typedef void* CPlaceholderGroup;

@@ -147,7 +149,7 @@ CreateRetrievePlanByExpr(CCollection c_col,
auto status = CStatus();
status.error_code = milvus::Success;
status.error_msg = "";
auto plan = (CRetrievePlan)res.release();
auto plan = static_cast<CRetrievePlan>(res.release());
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above. They are defined as void*

typedef void* CSearchPlan;
typedef void* CPlaceholderGroup;
typedef void* CRetrievePlan;

@alexanderguzhva
Copy link
Contributor

@abd-770 I've added some comments, let's wait until my colleagues make a review. Thanks.

@abd-770 abd-770 closed this Oct 2, 2024
@abd-770 abd-770 force-pushed the forkedMilvus-fixCast branch from 6e58ba0 to a05a37a Compare October 2, 2024 16:57
@sre-ci-robot sre-ci-robot added size/XS Denotes a PR that changes 0-9 lines. and removed size/L Denotes a PR that changes 100-499 lines. labels Oct 2, 2024
issue: milvus-io#35900

Signed-off-by: Abdullah Ahmed <abdullahdb6@gmail.com>
@abd-770 abd-770 reopened this Oct 2, 2024
@sre-ci-robot sre-ci-robot removed size/XS Denotes a PR that changes 0-9 lines. labels Oct 2, 2024
@sre-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: abd-770
To complete the pull request process, please assign wxyucs after the PR has been reviewed.
You can assign the PR to them by writing /assign @wxyucs in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot sre-ci-robot added size/L Denotes a PR that changes 100-499 lines. labels Oct 2, 2024
@mergify mergify bot added ci-passed and removed ci-passed labels Oct 2, 2024
@abd-770
Copy link
Contributor Author

abd-770 commented Oct 3, 2024

@alexanderguzhva I have made changes to the code based on your first review comment.
The rest, I have added respective reasons on the changes.

@abd-770
Copy link
Contributor Author

abd-770 commented Oct 8, 2024

@alexanderguzhva @godchen0212 @bigsheeper any updates?

@alexanderguzhva
Copy link
Contributor

@abd-770 I gave all of my comments. Waiting for my colleagues.

Copy link

stale bot commented Nov 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@stale stale bot added the stale indicates no udpates for 30 days label Nov 9, 2024
@mergify mergify bot removed the ci-passed label Nov 9, 2024
@abd-770
Copy link
Contributor Author

abd-770 commented Nov 15, 2024

Hey @alexanderguzhva @godchen0212 @bigsheeper ,
Can you guys review this pr? It's been over a month now, and marked stale.

@stale stale bot removed the stale indicates no udpates for 30 days label Nov 15, 2024
Copy link
Contributor

mergify bot commented Dec 2, 2024

@abd-770 go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link

stale bot commented Jan 3, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@stale stale bot added the stale indicates no udpates for 30 days label Jan 3, 2025
@alexanderguzhva
Copy link
Contributor

/reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-passed DCO check passed. kind/bug Issues or changes related a bug size/L Denotes a PR that changes 100-499 lines. stale indicates no udpates for 30 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants