Loading…

What errors can cause a C application crash

You have the source code of the application written in C, which crashes after launch. After ten starts in the debugger, you find that the application crashes each time in different places of the code. The application is single-threaded and uses only the standard C library. What errors can cause the application crashes? How will you check each one?

 

The solution mostly depends on the kind of diagnosed application. Still, we want to provide you with some general grounds for such random crashes.

 

  • “Random” variable: a program can use some “random” value or a component variable that does not have a specific exact value. Let’s check some examples: user input, a random number generated by the program, time of day, etc.

  • Uninitialized variable: an application can use an uninitialized variable, which in some programming languages ​​can take any value by default. Thus, the code can be executed differently each time.

  • Memory leak: the application may have exhausted all resources. Other reasons are random and depend on the number of processes running at a specific time. This may also include stack heap overflow or data corruption.

  • External reasons: the application may depend on another application, machine or resource. In case there are many such connections, then the application can crash at each point of time.

 

In order to determine the issue, you need to analyse the application as much as possible. Who runs the application? What do users do? What does the application itself perform?

 

Despite the fact the program does not crash in any particular code place, the crash may be provoked by particular components or scenarios. For instance, an application may be OK after launch, but the crash takes place once the particular file is uploaded. Moreover, the crash may happen in the responsibility area of low-level components, i.e. when we execute file I/O.

 

One of the effective ways to deal with such situations is to do random testing. Firstly, close all other running applications and take a look at all available resources. In case you can disable some application parts, then do it. Also, you can run the application on another PC or laptop and check if this error/crash appears. The more we can modify, the easier it is to find the issue.

 

Additionally, you can use special tools to test particular situations. For instance, in order to analyze the reasons of type 2 errors, you can use debuggers that check the application code for uninitialized variables. 

 

Before-mentioned challenges give you an opportunity to demonstrate both mental abilities and your work style. Do you constantly jump from one to another and make random assumptions? Or do you try to find the solution logically?


Leave a Comment