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

Критерий -- поиск goto (часть 1) #18

Closed
mirrin00 opened this issue Jan 19, 2024 · 2 comments · Fixed by #28
Closed

Критерий -- поиск goto (часть 1) #18

mirrin00 opened this issue Jan 19, 2024 · 2 comments · Fixed by #28

Comments

@mirrin00
Copy link

goto -- в общем случае плохо и используется не по назначению. Нужно кидать предупреждение при использовании goto

Пример плохо кода:

int do_smth_cool(int x){
    int val = some_func(x);
    if(val > 0) goto label;
    x /= 2;
label:
    return x + val;
}

Как должно быть:

int do_smth_cool(int x){
    int val = some_func(x);
    if(val <= 0){
        x /= 2;
    }
    return x + val;
}
@mirrin00
Copy link
Author

Надо бы проверить, что данной проверки ещё нет в oclint

@jcdkiki
Copy link
Collaborator

jcdkiki commented Feb 7, 2024

Такая проверка действительно уже есть в OCLint.

jcdkiki@pc:~/code/oclint_extensions/examples$ ./test-gcc.sh ex-goto


OCLint Report

Summary: TotalFiles=1 FilesWithViolations=1 P1=0 P2=0 P3=2

/home/jcdkiki/code/oclint_extensions/examples/ex-goto/main.cpp:9:14: goto statement [basic|P3]
/home/jcdkiki/code/oclint_extensions/examples/ex-goto/main.cpp:6:2: short variable name [naming|P3] Length of variable name `x` is 1, which is shorter than the threshold of 3

[OCLint (https://oclint.org) v22.02]

ex-goto/main.cpp:

#include <iostream>
using namespace std;

int main()
{
	int x;
	cin >> x;

	if (x != 2) goto failed;
	cout << "Congrats! You typed 2!" << endl;

failed:
	return 0;
}

Критерий называется GotoStatmentRule.

@jcdkiki jcdkiki closed this as completed Feb 7, 2024
@jcdkiki jcdkiki reopened this Feb 10, 2024
@jcdkiki jcdkiki linked a pull request Jul 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants