The SAMATE Project Department of Homeland Security
Downloads:  Selected

Back to the previous page...Back to the previous page

Test Case IDCandidate19
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorSecureSoftware
LanguageC
Type of test caseSource Code
Input stringN/A
Expected OutputMax unsigned int: 4294967295 ffffffff Now signed: -1 ffffffff
InstructionsN/A
Submission date2005-10-21
DescriptioniconInteger coercion refers to a set of flaws pertaining to the type casting, extension,or truncation of primitive data types. (from TCCLASP-5_2_8_10)

Duplicate code of Test Case 3
Filename
Flaw
  • (?) CWE-118: Improper Access of Indexable Resource (Range Error) at line 4

There is no comments :: Submit a comment :: RSS

>./Integer_coercion_error.c
  1. #include <stdio.h>
  2. int main() {
  3. int value;
  4. value = (int)(~((int)0) ^ (1 << (sizeof(int)*8)));
  5. printf("Max unsigned int: %u %1$x\nNow signed: %1$d %1$x\n",
  6. value);
  7. return (0);
  8. /* The above code produces the following output:
  9. Max unsigned int: 4294967295 ffffffff
  10. Now signed: -1 ffffffff
  11. */
  12. }
  13.  
  14.  
  15.  
  16.  
  17.