Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . ( 6 points ) Consider the code below: 1 # include < stdio . h > 2 # include < stdlib . h

1.(6 points) Consider the code below:
1 # include < stdio .h >
2 # include < stdlib .h >
3
4 struct db_entry {
5 char * name ;
6 char * value ;
7};
8
9 void dbe_print ( struct db_entry * entry )
10{
11 fprintf ( stdout ,"%s =>%s
", entry -> name , entry -> value ) ;
12}
13
14 int main (int argc , char ** argv )
15{
16 struct db_entry * e ;
17 e -> name =" hocus pocus ";
18 e -> value =" focus ";
19 dbe_print ( e ) ;
20 return 0;
21}
This code compiles, but crashes when it is run. Suspecting a problem with dbe print,
you comment out the line of code that prints the entry (11), however the program still
crashes! You suspect the crash is caused by a memory allocation problem.
(a) What is the reason for the crash?
21 January 2024 Page 1
CSSE 132 Winter 2023-2024
(b) Without changing existing code, you can solve this problem by inserting additional
code to correct the crash and resolve the memory issue.
Indicate what code you would insert and the line numbers immediately before
where your code will be inserted. (For example, insert this code after line 19 or
insert this code just above line 9.)

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions