Page 210 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 210
Principles of Software Engineering
Notes 10.1.1 Synchronization Errors
In a parallel program, where there are multiple threads possibly accessing some common
resources, then synchronization errors are possible. These errors are very difficult to find as they
do not manifest easily. But when they do manifest, they can cause serious damage to the system.
There are different categories of synchronization errors, some of which are:
1. Deadlocks
2. Race conditions
3. Inconsistent synchronization
Deadlock is a situation in which one or more threads mutually lock each other. The most frequent
reason for the cause of deadlocks is inconsistent locking sequence the threads in deadlock wait
for resources which are in turn locked by some other thread. Race conditions occur when two
threads try to access the same resource and the result of the execution depends on the order of
the execution of the threads. Inconsistent synchronization is also a common error representing
the situation where there is a mix of locked and unlocked accesses to some shared variables,
particularly if the access involves updates. Some examples of these errors are given.
Array Index Out of Bounds
Array index often goes out of bounds, leading to exceptions. Care needs to be taken to see that
the array index values are not negative and do not exceed their bounds.
Arithmetic Exceptions
These include errors like divide by zero and floating point exceptions. The result of these may
vary from getting unexpected results to termination of the program.
10.1.2 Enumerated Data Types
Overflow and underflow errors can easily occur when working with enumerated types, and
care should be taken when assuming the values of enumerated data types. An example of such
an error is:
typedef enum {A, B,C, D:} grade;
void foo(grade x)
{
int 1,m;
1=GLOBAL_ARRAY[x–1]; /* Underflow possible */
m=GLOBAL_ARRAY(x+1); /* Overflow possible */
}
10.1.3 String Handling Errors
There are a number of ways in which string handling functions like strcpy, sprintf, gets etc can
fail. Examples are one of the operands is NULL, the string is not NULL terminated, or the source
operand may have greater size than the destination. String handling errors are quite common.
Buffer overflow
Though buffer overflow is also a frequent cause of software failures, in today’s world its main
impact is that it is a security flaw that can be exploited by a malicious user for executing arbitrary
code. When a program takes an input which is being copied in a buffer, by giving a large (and
malicious) input, a malicious user can overflow the buffer on the stack. By doing this, the return
204 LOVELY PROFESSIONAL UNIVERSITY