Question: Study the following program and answer the questions. int arrayCopy(int array[], int n) { unsigned char y = n * sizeof(int); int savedarray[y]; for(int i

Study the following program and answer the questions.

int arrayCopy(int array[], int n)
{
    unsigned char y = n * sizeof(int);
    int savedarray[y];
    for(int i = 0; i < n; i++){
        savedarray[i] = array[i];
    }
return 0; }

1. Is there any possibility of a buffer overflow in the above program and why? For what value of n the overflow will occur, assuming sizeof(int) = 2 ?

2. If there is a buffer overflow, will it be in the Stack or Heap? Explain your answer.

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution 1 The first line inside the function assigns a value to the unsigned ch... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!