Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your task The sanitizers / directory contains several buggy programs. For each of the programs below, your task is to: Compile the program as instructed
Your task
The sanitizers directory contains several buggy programs. For each of the programs below, your task is to:
Compile the program as instructed
Run the program until you get an error message from AddressSanitizer or MemorySanitizer
With help from the Sanitisers Guide, identify the following pieces of information from the error message:
The type of error, and what it means
The name of the function in which the error occurred, and the source file and line number of the instruction that triggered the error
The series of functions that were on the function call stack when the error occurred
The meaning of any other stack traces in the error message these usually have a line of pink text above them
Deduce what is wrong with the program but don't actually fix the program
In the file partanswers.txt under the heading for the program, paste the error message given by the program and briefly explain what the problem with the program is During lab marking, the notes you write in this file will be helpful.
Do not fix the programs the purpose of this task is to learn how to interpret error messages. During lab marking, your tutor will ask you to reproduce the error messages, which won't be possible if you have fixed the programs. Program : shuffleArray c
The purpose of this program is to read values into an array and then shuffle the array. Here is the intended
behaviour of the program:
$shuffleArray
Enter array size:
Enter array values:
Original array:
Shuffled array:
Note that the program randomly shuffles the array, so it is expected to produce different outputs each time it is run.
Compile the program with the following command:
$ clang Wall Werror g fsanitizeaddress, leak, undefined o shuffleArray shuffleArray.c
Hint: Note that unlike Program the error in this program will occur in a function that is not in the source code
as there is no function called scanfcommon in shuffleArray c This suggests that the error occurred in
a library function. In this case, you should look further down the function call stack until you find a function that
exists in the source code. Reads in values, then outputs them in random order
#include
#include
#include
void shuffleint arr int size;
void printArrayint arr int size;
int mainvoid
srandtimeNULL;
printfEnter array size: ;
int maxVals ;
if scanfd &maxVals maxVals
fprintfstderr "error: invalid array size
;
int vals mallocmaxVals;
if vals NULL
fprintfstderr "error: out of memory
;
exitEXITFAILURE;
printfEnter array values: ;
int numVals ;
while numVals maxVals && scanfd &valsnumVals
numVals;
printfOriginal array: ;
printArrayvals numVals;
shufflevals numVals;
printfShuffled array: ;
printArrayvals numVals;
freevals;
Randomly shuffles the given array
void shuffleint arr int size
for int i ; i size; i
int j randi ;
int tmp arrj;
arrj arri;
arri tmp;
Prints the given array
void printArrayint arr int size
printf;
for int i ; i size; i
if i
printf;
printfd arri;
printf
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started