You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue documents a case where the execution of a program compiled by dcc stops without providing the usual dcc explanation.
Context
This case was contrived after investigating a UNSW COMP1511 student's post on the 2024 Term 2 edstem forum (post #598). It highlights the worst case. Minor variations to the sample code exhibit varying behaviour.
Steps to Reproduce
Compile the below code with dcc -o dcc_no_explanation dcc_no_explanation.c
Run the program with ./dcc_no_explanation and input y several times, followed by any other character to quit
The program repeatedly attempts to modify out-of-bounds elements in a 2D array
// dcc_no_explain.c// Description: a program to repeatedly modify out-of-bounds elements in a 2D array#include<stdio.h>#defineSIZE 10
#defineSTART -1
#defineEND 0
// repeatedly modify elements in first column of array between rows START and ENDvoidcommand_loop(intarray[SIZE][SIZE]) {
charcommand;
printf("Do you want to modify out-of-bounds elements? (y/n)\n");
while (scanf(" %c", &command) ==1&&command=='y') {
for (inti=START; i<END; i++) {
array[i][0] =1;
}
printf("Do it again? (y/n)\n");
}
}
intmain(intargc, char*argv[]) {
intarray[SIZE][SIZE] = {0};
command_loop(array);
return0;
}
Expected Behavior
Ideally, the program would exit with an explanation that describes the error.
Example of expected output:
$dcc -o dcc_no_explain dcc_no_explain.c && ./dcc_no_explain
Do you really want to modify out-of-bounds elements? (y/n)
y
Runtime error: index -1 out of bounds for type 'int[10][10]'
dcc explanation: You are using an illegal array index: -1
Valid indices for an array of size 10 are 0..9
Make sure the size of your array is correct.
Make sure your array indices are correct.
Execution stopped in main() in dcc_no_explain.c at line XYZ:
etc etc.. (more explanation + gdb output of local variables)
$
Actual Behavior
The program allows repeated access to out-of-bounds elements and produces a limited error message only after the while loop terminates. This may confuse novice programmers who expect error messages to appear immediately or close to the point where the error occurs.
Example of actual output:
$dcc -o dcc_no_explain dcc_no_explain.c && ./dcc_no_explain
Do you really want to modify out-of-bounds elements? (y/n)
y
Do it again? (y/n)
y
Do it again? (y/n)
y
Do it again? (y/n)
n
Execution stopped because of an invalid pointer or string.
$
Screenshots or Logs
N/A
Environment
Linux 6.1.0-23-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.99-1 (2024-07-15) GNU/Linux
dcc version 2.35
The text was updated successfully, but these errors were encountered:
Description
This issue documents a case where the execution of a program compiled by dcc stops without providing the usual dcc explanation.
Context
This case was contrived after investigating a UNSW COMP1511 student's post on the 2024 Term 2 edstem forum (post #598). It highlights the worst case. Minor variations to the sample code exhibit varying behaviour.
Steps to Reproduce
dcc -o dcc_no_explanation dcc_no_explanation.c
./dcc_no_explanation
and inputy
several times, followed by any other character to quitExpected Behavior
Ideally, the program would exit with an explanation that describes the error.
Example of expected output:
Actual Behavior
The program allows repeated access to out-of-bounds elements and produces a limited error message only after the
while
loop terminates. This may confuse novice programmers who expect error messages to appear immediately or close to the point where the error occurs.Example of actual output:
Screenshots or Logs
N/A
Environment
The text was updated successfully, but these errors were encountered: