subject
Engineering, 14.02.2020 20:15 desi9750

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";
}
#DEFINE PASSWORD correct horse battery staple char *check_permissions (char *user_guess) f if (user_guessPASSWORD) return

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

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

int main )( char *x malloc (0xsizeof (char));

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

int foo ) int *x = malloc (20); 2 + X x[3]99; return x[3];

5) int main () {

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

ansver
Answers: 1

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, niyawilliams23
Asingle-geared blanking press has a stroke of 200 mm and a rated capacity of 320 kn. a cam driven ram is assumed to be capable of delivering the full press load at constant force during the last 15 percent of a constant-velocity stroke. the camshaft has an average speed of 90 rev/min and is geared to the flywheel shaft at a 6: 1 ratio. the total work done is to include an allowance of 16 percent for friction a) estimate the maximum energy fluctuation b) find the rim weight for an effective diameter of 1.2 m and a coefficient of speed fluctuation of 0.10
Answers: 1
image
Engineering, 04.07.2019 18:10, salazjlove
Which of the following refers to refers to how well the control system responds to sudden changes in the system. a)-transient regulation b)- distributed regulation c)-constant regulation d)-steady-state regulation
Answers: 1
image
Engineering, 04.07.2019 18:10, demarcuswiseman
Calculate the bore of a cylinder that has a stroke of 18 inches and an extension time of 6 seconds at a flow rate of 4 gal/min.
Answers: 3
image
Engineering, 04.07.2019 19:10, kimmy6973
What is creep? what is stress relaxation?
Answers: 1
You know the right answer?
Common Mistakes in C

5 Points

Each of the following code samples below is ma...

Questions in other subjects:

Konu
Mathematics, 08.12.2020 01:00
Konu
Engineering, 08.12.2020 01:00