Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ , Find and fix the bug and Problem: #include using namespace std; const int MAXSIZE = 16; static int array1[MAXSIZE]; static int i; //

C++ , Find and fix the bug and Problem:

#include  using namespace std; const int MAXSIZE = 16; static int array1[MAXSIZE]; static int i; // bad idea too call a global variable i! void initArray(int[], int); void printArray(int[]); // This initializes element arr[i] to val for each array element void initArray(int arr[], int val) { for (i=MAXSIZE; i >= 0; i--) arr[i] = val; return; } // This prints the contents of the argument array, with each element printed as "index: value" on its own line // For example, a 4-element array containing {10,11,12,13} would print as: // 0: 10 // 1: 11 // 2: 12 // 3: 13 void printArray(int arr[]) { ... }; int main() { int dummy; initArray(array1, 5); // fill array1 with fives int *array2 = array1; // make a copy (clone) the array in a new array array1[0]=99; // change the element [0] of the array1 array2[1]=888; // change the element [1] of the array2 // print out both arrays cout << endl << "array1:" << endl; printArray(array1); cout << endl << "array2:" << endl; printArray(array2); return 0; }; 

One problem resulted from a buffer overflow error. This is a common security error since it allows malicious code to access memory locations that they should not have access to. That memory location might have a function parameter, or even machine code for the program that can now be overwritten with malicious code!

Download the source file: https://www.dropbox.com/s/31qx8qykgeskjm6/10.cpp?dl=0

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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions