Question
Q6 Common Mistakes in C 5 Points Each of the following code samples below is making a common mistake in C. From the options: probable
Q6 Common Mistakes in C
5 Points
Each of the following code samples below is making a common mistake in C. From the options:
probable segfault, double free, incorrect use of free, logic error, memory leak, and no error
select the error type that best categorizes the mistake.
You can assume all the code has the necessary #include macros. Also you should assume that the system is 32-bit.
1) #DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) { if (user_guess = PASSWORD) { return "access granted"; } return "access denied"; }
2) #DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) { if (user_guess == PASSWORD) { return "access granted"; } return "access denied"; }
3) int main () { char *x = malloc(0xFFFFFFFF * sizeof(char)); x[0] = '!'; }
4) int foo () { int *x = malloc(20); x[0] = x[1] = 1; x[2] = x[0] + x[1]; x[3] = 99; return x[3]; }
5) int main () {
char *x = "patrick"; printf("%s", x); free(x); // tidy up }#DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) f if (user_guessPASSWORD) return "access granted" return "access denied"; #DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) if (user_guess PASSWORD) return "access granted"; return "access denied"; int main )( char *x malloc (0xFFFFFFFFsizeof (char)); int foo ) int *x = malloc (20); 2 + X x[3]99; return x[3]; int main ) char *x "patrick"; printf ( " %s " , x ) ; free(x): 17 tidy up
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started