Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a case where the expected "dcc explanation" output is not generated #102

Open
AndrewPolak opened this issue Sep 8, 2024 · 0 comments
Open

Comments

@AndrewPolak
Copy link

AndrewPolak commented Sep 8, 2024

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

  1. Compile the below code with dcc -o dcc_no_explanation dcc_no_explanation.c
  2. Run the program with ./dcc_no_explanation and input y several times, followed by any other character to quit
  3. 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>

#define SIZE 10
#define START -1
#define END 0

// repeatedly modify elements in first column of array between rows START and END
void command_loop(int array[SIZE][SIZE]) {
    char command;
    printf("Do you want to modify out-of-bounds elements? (y/n)\n");
    while (scanf(" %c", &command) == 1 && command == 'y') {
        for (int i = START; i < END; i++) {
            array[i][0] = 1;
        }
        printf("Do it again? (y/n)\n");
    }
}

int main(int argc, char *argv[]) {
    int array[SIZE][SIZE] = {0};
    command_loop(array);
    return 0;
}

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant