|
From: João M. S. S. <joa...@gm...> - 2015-01-02 00:40:07
|
> Tom Hughes' suggestion to fix the invalid file descriptor first is > valid. A memory overwrite can cause all kinds of problems (what if you > overwrote 1 million characters of the buffer?) and many of the results > afterward will be unreliable. Your program may appear to run correctly > once, but it is a disaster waiting to happen. The invalid file descriptor comes from this buffer overrun. Writing after the command buffer overwrites the file descriptor value. I've fixed it by using C++ strings, since there are no performance issues from that specific line. > The procedure for cleaning up a program is to fix all of the problems > you know how to fix, then rerun valgrind. Repeat until all errors are > gone. Errors late in a program's run may have been caused by earlier > errors. New errors may appear after you fix the initial set of > problems; they were simply masked by the previous errors. Yes, I normally do that. I have 0 errors and 0 warnings from gcc with a reasonable set of switches: -Wall, -Wextra, -Wpedantic. Then I run cppcheck with 0 errors/warnings. Then valgrind with 0 memory errors, and from time to time eliminate all leaks. There are only leaks from other libraries. > You are on the right track; you need to keep at it. There have been > times when I've had so many problems in so many places that I simply > fixed the first one and reran valgrind. In your case, the "bad file > descriptor" error was a symptom of another problem, not a cause. Once > you fix that you can move on to any other problems that may appear. Yes, I remember when I first wrote a C program (back in 1995) and got more than one hundred errors and despaired. Then I fixed one bracket and almost all of them were gone :) At that time we used pico in a monochrome terminal :P I miss that "ASCII" feeling :) -- João M. S. Silva |