Question

In: Computer Science

Question 3. In the following code, answer these questions: Analyze the code and how it works?...

Question 3. In the following code, answer these questions:

  1. Analyze the code and how it works?
  2. How can we know if this code has been overwritten? Justify how?

#include <stdlib.h>

#include <unistd.h>

#include <stdio.h>

int main(int argc, char **argv)

{

int changed = 0;

char buff[8];

while (changed == 0){

gets(buff);

if (changed !=0){

break;}

else{

    printf("Enter again: ");

    continue;

}

}

     printf("the 'changed' variable is modified\n %d", changed);

}

END of the questions

:::::::::::::::::::::::::: ::::::::::::::::::::::::::

Submission

For this assignment, you need to write a report file of your work. The report should answer each question in details, providing outputs of the code to justify your answer.

Solutions

Expert Solution

a) initally the variable changed is assigned with 0 and is never updated later on in the code.

so the while loop loops forever(infinitely) taking the input into the char array (string) buff every time the loops runs

---> Here gets() is used so the function takes even the string of length greater than 8 but only the first 8 getting stored in the char array buff and remained buffer overflowed

the compiler throws a warning because of gets and it is not secure to use gets instead we could use fgets in which we will be specifing the length of the input string

b)there no way to know  whether the string has been modified or not because we are not outputting the string


Related Solutions

Question 3: Answer the following questions:                                   &n
Question 3: Answer the following questions:                                                               A. In a perfectly competitive market, explain why each firm in this market is a Price Taker and define this concept; and explain what kind of a demand curve faces each firm in this market                                                                                                                               1. Define and explain the concept of Price Taker                                                        ……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… 2. Demand curve for a perfectly competitive firm                                                       ……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… ……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… B. Explain the two kinds of barriers (Legal Barrier to Entry)(Natuarl Barriers to Entry) to entry that exist...
Instructions: Answer each of the following questions: Question: Use the AD-AS model to analyze the effects...
Instructions: Answer each of the following questions: Question: Use the AD-AS model to analyze the effects of each of the following events on equilibrium Y and P in the short-run and in the long-run: The government announces a 1% decrease of VAT (Value-added Tax) There are new advances in technology that allows for more efficient production of oil
Watch the video How Cells Divide and How Chemotherapy Works and answer the following questions: What...
Watch the video How Cells Divide and How Chemotherapy Works and answer the following questions: What does it mean that the chemotherapy treatment is nonspecific? Find an example of a specific method of a treatment for cancer. How does it work?
Run the following code and answer the following questions: (a) How do accuracy change with changing...
Run the following code and answer the following questions: (a) How do accuracy change with changing the tree maximum depth? [Your answer] (b) What are the ways to reduce overfitting in a decision tree? [Your answer] from sklearn import datasets import numpy as np from sklearn.model_selection import train_test_split from sklearn.tree import plot_tree iris = datasets.load_iris() X = iris.data[:, [2, 3]] y = iris.target X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, random_state=1, stratify=y) tree = DecisionTreeClassifier(criterion='entropy', max_depth=10, random_state=1) tree.fit(X_train,...
Question 3: Answer the following short question    Questions 3(a): A milk producing factory has four...
Question 3: Answer the following short question    Questions 3(a): A milk producing factory has four sensors, First sensor (A) checks the color of milk and if the color is good it turns ON. Second sensor (B) checks if the label (sticker) of company is correctly pasted and turns ON. Third sensor (C) checks if the cap of bottle is properly closed and turns ON. Fourth sensor (D) checks if the weight of the bottle is correct and turns ON...
Question 3: Answer the following short question    Questions 3(a): A milk producing factory has four...
Question 3: Answer the following short question    Questions 3(a): A milk producing factory has four sensors, First sensor (A) checks the color of milk and if the color is good it turns ON. Second sensor (B) checks if the label (sticker) of company is correctly pasted and turns ON. Third sensor (C) checks if the cap of bottle is properly closed and turns ON. Fourth sensor (D) checks if the weight of the bottle is correct and turns ON...
Analyze the following three-bond portfolio and answer the following questions:
Analyze the following three-bond portfolio and answer the following questions:BondsPercent of PortfolioTreasuries25%Corporate AAA50%Mortgage-backed25%a. If the portfolio duration is 11.5, what is the percent contribution to spread duration of the Treasury-sector bonds?b. Evaluate the various convexity calculations and how those would affect the duration of the individual bonds and this portfolio of bonds (without needing to make calculations). Also analyze the advantages and disadvantages of using key rate and effective duration.
subject: International business Q. No. 3 Analyze the following situation and answer the questions given below...
subject: International business Q. No. 3 Analyze the following situation and answer the questions given below Max Marks 10 Should We Allow Global Corporation to Set Up a Factory in our Country? About the business.  Global Corporation is applying for planning permission to build a factory in your country. The factory is expected to be very profitable. 1000 new jobs should be created for assembly-line work. Many of the goods made could be sold abroad. Some of the supplies for the...
Topic: Interpersonal Communication Analyze the movie, The Breakfast Club, and answer the following question: How was...
Topic: Interpersonal Communication Analyze the movie, The Breakfast Club, and answer the following question: How was interaction coordination utilized in the film? IF it was not utilized by one of the main characters, how should or could have it been used to enhance communication?
  Answer the questions related to the following code:             Class B             {      &nbs
  Answer the questions related to the following code:             Class B             {                         Public:                                     Void b1();                         Protected:                                     Void b2();             };             Class A : public B             {                         Public:                                     Void  a1();                         Protected: Void  a2();             };             Class C: public A               {                         Public:                                     Void c1();             }; Void main () { B temp1; A temp2; C temp3; }    Name all member functions of all classes visible through temp1 in the main function? Name all member functions of all classes visible through temp2 in the main function? Name all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT