The SAMATE Project Department of Homeland Security
Downloads:  Selected

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

Test Case IDCandidate20
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorSecureSoftware
LanguageC
Type of test caseSource Code
Input stringN/A
Expected OutputInt MAXINT: 2147483647 Short MAXINT: -1
InstructionsN/A
Submission date2005-10-21
DescriptioniconTruncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion. (from TCCLASP-5_2_9_10)
Filename
Flaw
  • (?) CWE-118: Improper Access of Indexable Resource (Range Error) at line 6

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

>./Truncation_error.c
  1. #include <stdio.h>
  2. int main() {
  3. int intPrimitive;
  4. short shortPrimitive;
  5. intPrimitive = (int)(~((int)0) ^ (1 << (sizeof(int)*8-1)));
  6. shortPrimitive = intPrimitive;
  7. printf("Int MAXINT: %d\nShort MAXINT: %d\n",
  8. intPrimitive, shortPrimitive);
  9. return (0);
  10.  
  11. /* The above code produces the following output:
  12. Int MAXINT: 2147483647
  13. Short MAXINT: -1
  14. */}
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.