Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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"; } 

image text in transcribed

2) #DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) { if (user_guess == PASSWORD) { return "access granted"; } return "access denied"; } 

image text in transcribed

3) int main () { char *x = malloc(0xFFFFFFFF * sizeof(char)); x[0] = '!'; }

image text in transcribed

4) int foo () { int *x = malloc(20); x[0] = x[1] = 1; x[2] = x[0] + x[1]; x[3] = 99; return x[3]; }

image text in transcribed

5) int main () {

 char *x = "patrick"; printf("%s", x); free(x); // tidy up } 

image text in transcribed

#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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

14-18 Compare the two major types of planning and control tools.

Answered: 1 week ago