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

Detect System.arraycopy with shift #662

Open
Luro02 opened this issue Dec 17, 2024 · 0 comments
Open

Detect System.arraycopy with shift #662

Luro02 opened this issue Dec 17, 2024 · 0 comments
Labels
bug Something isn't working false-negative A lint should trigger on code that is wrong.

Comments

@Luro02
Copy link
Collaborator

Luro02 commented Dec 17, 2024

Summary

See examples below.

Lint Name

USE_SYSTEM_ARRAYCOPY

Reproducer

    public static String rotateString(String word, int positions) {
        String[] letters = word.split("");
        int pos = positions % word.length();
        String[] newword = new String[word.length()];
        for (int i = word.length() - pos; i < word.length(); i++) {
            newword[i - word.length() + pos] = letters[i];
        }
        for (int i = pos; i < word.length(); i++) {
            newword[i] = letters[i - pos];
        }
        return String.join("", newword);
    }

Here it could detect both, not sure how difficult that is to implement.

This is a simpler example:

    public static void main(String[] args) {
        String[] vectors = new String[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            vectors[i - 1] = args[i];
        }
    }
@Luro02 Luro02 added bug Something isn't working false-negative A lint should trigger on code that is wrong. labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false-negative A lint should trigger on code that is wrong.
Projects
None yet
Development

No branches or pull requests

1 participant