Error replication on a client machine

I am currently studying C at university. I was instructed to write a program in C, which gives the correct output on my PC and on the university computer, but not on the professor’s PC. The professor gave me information about my program on his PC, and he instructed me to find the error.

I looked at the logic and the expected result, and there is no correlation between them. Of course, this is not a logical mistake if it works on 2 out of 3 computers.

When I asked the professor to mark the task based on the school computer, he did not agree and talked about the real world, that if it does not work on only one computer, my program does not work.

So, I want to ask real-world professionals what they will do in this situation? How can you debug a program if the program does not work on the tool provided to you for testing? That is, if a client reports an error that you cannot reproduce yourself, what can you do? Or how are you going to replicate the error?

FYI, my computer is windows, the school computer is Linux, and the professor's computer is Mac.

+6
source share
3 answers

I looked at the logic and the expected result, and there is no correlation between them. Of course, this is not a logical mistake if it works on 2 out of 3 computers.

Welcome to Undefined Behavior: unfortunately, the fact that your program gives the correct results on two (or two thousand, for that matter) computers proves nothing. The language standard tried to give compiler developers more freedom to optimize so that the effectiveness of C ++ programs could remain competitive with programs written in assembly language. Unfortunately, this leaves a lot of room for incompatibility between platforms: different compilers and runtimes can generate completely different results for programs with errors. The worst part is that programs with errors can lead to behavior that you can reasonably expect on some platforms, and fail miserably on others!

The only way to protect Undefined behavior is to write the right programs. Compilers intelligently help you by creating warnings where they believe that Undefined behavior can occur. Include all warnings at the highest level, compile your program and fix all warnings reported by the compiler. Most likely, some of the warnings will explain the differences between the output on your computer and your professor's computer.

To track advanced errors, use valgrind . This program will help you identify problems related to memory, such as writing to a selected area, using released memory, freeing the same piece of memory several times, etc.

+5
source

1) Defensive programming. Do not think that everything will work. Do you need to open a file? Make sure it exists. Are you loading a data structure? Verify that the data structure is correct.

1a) Significant user errors: if the file is missing, show the user "Could not find the file" file.txt "in the path C: \ items". Do not keep going forward.

2) As indicated in the comment, write down everything. More for a school project (where performance is not critical), write everything to a file and check what the path your program is following and (when possible) why (what are the values ​​of the data structure).

2a) Given the close relationship, you can define a test case for a professor who will run on his computer. Check your journal against yours.

+2
source

I am definitely not a “real world professional”, but I will try (and, of course, comment):

First, I will look at the code and try to find out if there are any “undefined behaviors" there. see @ dasblinkenlight answer.

Secondly, I will look for OS-specific code. hard-coded path separators sizeof s, small to large finite problems, etc.

Thirdly, I would try to find a similar car. Of course, this may be original, but since it is not available, you can search for virtual machine images or check if Amazon can give you something like this (they do, but I don’t know which OSs are available; suppose OS X is not )

Forth, I would try to create a version downloaded with the help of debugging and logging assistants, and pass it on to the client if he wants to give a hand.

+1
source

Source: https://habr.com/ru/post/946331/


All Articles