Apply suggestions from code review

Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
This commit is contained in:
ihsinme
2022-03-01 10:49:36 +03:00
committed by GitHub
parent 0c8a07218c
commit d772ea0efe
3 changed files with 12 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ int scanf(const char *format, ...);
int globalVal;
int functionWork1() {
int i;
if (scanf("%i", i) == 1) // GOOD
if (scanf("%i", &i) == 1) // GOOD
return i;
else
return -1;
@@ -11,7 +11,7 @@ int functionWork1() {
int functionWork1_() {
int i;
int r;
r = scanf("%i", i);
r = scanf("%i", &i);
if (r == 1) // GOOD
return i;
else
@@ -20,25 +20,25 @@ int functionWork1_() {
int functionWork1b() {
int i;
scanf("%i", i); // BAD
scanf("%i", &i); // BAD
return i;
}
int functionWork2() {
int i = 0;
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
scanf("%i", &i); // GOOD:the error can be determined by examining the initial value.
return i;
}
int functionWork2_() {
int i;
i = 0;
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
scanf("%i", &i); // GOOD:the error can be determined by examining the initial value.
return i;
}
int functionWork2b() {
int i;
scanf("%i", i); // BAD
scanf("%i", &i); // BAD
globalVal = i;
return 0;
}