Page 211 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 211
Unit 10: Coding Standards
address can get rewritten to what-ever the malicious user has planned. So, when the function Notes
call ends, the control goes to where the malicious user has planned, which is typically some
malicious code to take control of the computer or do some harmful actions. Basically, by exploiting
the buffer overflow situation, a malicious user can execute arbitrary code. The following code
fragment illustrates buffer overflow:
void mygets (char *str) {
i n t c h ;
while (ch = getchar () ! ='\n' && ch !='\0')
*(str++) = ch;
*str ='\0';
}
main () {
char s2 [4] ;
} mygets (s2) ;
10.2 Structured Programming
Structured (or modular) programming techniques shall be second-hand. GOTO statements shall
not be old as they lead to “spaghetti” code, which is hard to read and uphold, except as outlined
in the FORTRAN Standards and Guidelines.
Structured programming techniques assist the programmer in writing effectual error free
programs.
The elements of structured of programming include:
• Top-down development
• Modular design.
The Structure Theorem:
It is possible to write any computer program by using only three (3) basic control structures,
namely:
• Sequential
• Selection (if-then-else)
• Repetition (looping, DoWhile)
10.2.1 Algorithms
An algorithm is a sequence of precise instructions for solving a problem in a finite amount of time.
Properties of an Algorithm:
• It must be precise and unambiguous
• It must give the correct solution in all cases
• It must eventually end.
Algorithms and Humans
Algorithms are not a natural way of stating a problem’s solution, because we do not normally
state our plan of action.
LOVELY PROFESSIONAL UNIVERSITY 205