10

This is a followup to How can we improve "segmentation fault" questions?.

We are having a lot of questions about segmentation fault in C and C++. Some examples within 12 hours of this post are:

Why do I get a segmentation fault in this code with a signal handler?, BMP transformation seg fault - alloc or something else, and Segmentation fault in function that reads file and with threads. I am quite tired of seeing all these somewhat duplicate, but not so quite duplicate, posts again and again, as most problems can be solved by the following procedure:

  1. Read the code carefully (98% of problems ends here)
  2. Run Valgrind (or whatever memory checkers you like) (99.8% of problems ends here)
  3. Get a core dump and do a backtrace

It appears that people either do not know how to debug or just don't want to; and just dump whatever code that is segfaulting onto Stack Overflow. I suggest that we get a megathread about these segmentation fault questions, how to solve them, and restrict the dumping of code to Stack Overflow to use the community as an AI debugger, for the following reasons:

  1. A question about the issue of a specific piece of code is generally not useful for others, as they are too specific (this is especially true for segfault type of issues)
  2. Stack Overflow is a not free debugging service or AI debugger
  3. There is really no sense to waste everyone's time reading 200+ lines of code only to find out one missed a * when operating a pointer
  4. The answer to most of these questions are going to be the same (read, Valgrind, core dump)
  5. Otherwise there will be one day when the error message of segmentation fault becomes Segmentation fault (code dumped to Stack Overflow).

Note: in case one does not notice, the default segfault error message is Segmentation fault (core dumped).

16
  • 5
    Finding where a segfault happens is easy. Tracking down the cause of the fault may not be, and is not something that new developers can easily do, especially when it is intermittent. (Partly attributable to the lack of any teachable debugging in many educational curriculums.) May 4, 2020 at 1:32
  • 1
    Did anyone create a canonical question (as suggested in an answer to the linked question)? If not, why not write and self-answer one yourself? May 4, 2020 at 2:54
  • @Robert here is one for why code segfaults May 4, 2020 at 2:56
  • @Robert currently there appears to have none about how to debug segfaulting programs. May 4, 2020 at 2:57
  • That has a community wiki answer, you could always edit and expand/improve it. You have 100 rep, which is all it takes. May 4, 2020 at 3:02
  • @Robert The entire idea is to restrict code dump. What should I do after editing the wiki? May 4, 2020 at 3:33
  • 4
    The Java tag has What is a NullPointerException, and how do I fix it?. Why couldn't there be a similar one for C/C++? The root cause is similar. In the third example someone has followed the null pointer (I far as I can see) - never follow the null pointer, BTW. May 4, 2020 at 3:58
  • 2
    @Peter we have one here, but people dump code anyway May 4, 2020 at 4:04
  • 1
    Corresponding meta question: NullPointers - add links to what it is and the tag (similar to regex) May 4, 2020 at 4:04
  • No most people can't debug, for that you need experience and a lot of intuition. It is quite normal to get repeated questions, where the one or other detail of the same questions is asked and gets hopefully a good answer. What we are, hmm people with too much time on our hands and we like to get interesting problems and reputation. For someone who is here only two month it is actually quite funny to read that you are fed up.
    – nbk
    May 4, 2020 at 8:34
  • 5
    We need people to flag and vote to close questions as duplicates. That's what's missing. It's no secret that a lot of users would rather spend time answering questions than searching for duplicates. You get rep and thanks (from the OP and others who don't care about the long-term goal for the site) for doing the former, no rep and vilification for doing the latter (most of the time). May 4, 2020 at 12:05
  • @nbk the idea is that (say on math.SE) even if great research effort is shown, it is not of community interest to have questions like "integral of $\frac {dx} {2x^2+5}$. Help" sort of questions every day. One would rather have a megathread "How to calculate integral in the form $\int \frac {dx} {ax^2+b}$". The same applies to stack overflow. May 4, 2020 at 14:03
  • 3
    segfault is just one of many categories of debugging questions asked on Stack Overflow with insufficient information to solve them. May 4, 2020 at 14:23
  • 2
    @nbk: Playing twenty questions with a segfault OP has got to be the hardest possible way to earn reputation points. May 4, 2020 at 15:11
  • 1
    @RobertHarvey playing with 400 mysql question is the same, nevertheless i try , despite downvotes, highreps that answer many questions and null votes at all. It is the charm of the site. Bu tback ti teh question yeah make an canno9nical thread that answer 99 prozent of teh question, so that who want can refer it as Dup or comment
    – nbk
    May 4, 2020 at 15:46

0

You must log in to answer this question.

Browse other questions tagged .