Robust & Secure Programming Flashcards

All 24 cards in this deck

What is a logic error?

An error where the program runs but does not do what is expected, e.g. it gives an incorrect or unexpected output.

Give two examples of syntax errors in code.

Misspelling a keyword (e.g. OUPTUT for OUTPUT) and a missing bracket or quotation mark.
Also: using a keyword such as FOR as a variable name, or spaces in a variable name.

Give two examples of logic errors in code.

Using the wrong operator (e.g. < where ≤ is needed, or AND instead of OR) and creating an infinite loop.
Also: brackets in the wrong place in a calculation, or a loop that runs the wrong number of times.

True or false? A program containing a syntax error will still run but give the wrong answer.

False. A program will not run with a syntax error; it is a logic error that runs but gives incorrect results.

What are the steps to identify and correct a logic error in a given algorithm?

e.g. line 3 reads total ← num1 - num2 but the two numbers should be added

  1. Compare what each line does with what the algorithm should do: line 3 subtracts
  2. State the line number: line 3
  3. Give the corrected line, or an unambiguous description of the change: total ← num1 + num2

What is meant by a robust program?

A program that keeps working correctly, without crashing, whatever data is entered, e.g. because it validates its inputs. Robust does not mean easy to read.

What is authentication?

Confirming the identity of a user, e.g. checking that the username and password entered match the details stored for that user.

What are the steps in a simple authentication routine?
e.g. logging in to a school booking system

  1. Get the user to enter a username and a password.
  2. Compare both with the username and password stored (in plain text) for that user.
  3. If both match, grant access; if not, display an error and ask again.

What is data validation?

Checking that data entered is sensible and allowed before the program uses it, e.g. checking that a rating is in the range 1 to 10.

What does a range check do?
e.g. a height in cm must be from 40 to 180

Checks the value entered lies between a stated lower and upper limit — here, that the height is at least 40 and no more than 180.

What does a presence check do?

Checks that data has actually been entered, i.e. the input is not an empty string.

What does a length check do?

Checks that the data entered has an allowed number of characters, e.g. a password of at least 8 characters.

What are the steps to write an algorithm that validates an input and re-prompts until it is valid?
e.g. a height in cm must be from 40 to 180

  1. Input the value: height ← STRING_TO_INT(USERINPUT)
  2. Loop while it is outside the range: WHILE height < 40 OR height > 180
  3. Inside the loop, output an error message and input the value again; the loop (ENDWHILE) ends when the value is valid.

True or false? IF height ≥ 40 AND ≤ 180 THEN is a correct range check.

False. The variable must be repeated in each comparison: IF height ≥ 40 AND height ≤ 180 THEN.

What is the purpose of testing a program?

To check the program works as expected and gives the correct output for all inputs, and to find and remove errors before release.

What columns should a test plan contain?

The type of test (normal, boundary or erroneous), the test data, the expected result and the actual result.

What is a syntax error?

A mistake in the grammar of the code: it breaks the rules of the programming language, so the program cannot be translated or run.

What is normal (typical) test data?

Typical data that the program should accept and process correctly, e.g. 5 when the allowed range is 1 to 10.

What is boundary (extreme) test data?

Data at the limits of the allowed range and just either side of them. For an allowed range of 1 to 10, the boundary data is 0, 1, 10 and 11.

What is erroneous test data?

Data that the program should reject, e.g. data of the wrong type such as letters where a number is needed, or a value well outside the allowed range.

A program accepts whole-number heights from 40 cm to 180 cm. What is the boundary test data, and what should happen to each value?

39, 40, 180 and 181. 40 and 180 should be accepted; 39 and 181 should be rejected.

True or false? Writing "a value between 40 and 180" in the test data column of a test plan is acceptable.

False. Test data must be actual data, e.g. 50, not a description of the data.

Why can't a translator detect a logic error?

Code with a logic error still obeys the language's rules, so it translates and runs. Logic errors are found by testing or a trace table instead.

What is a test plan?

A document, written before testing begins, that sets out how a program will be tested and which test data will be used.