Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Code Block
bgColor#FFCCCC
double currentBalance; // User's cash balance 

void doDeposit(String userInput){
  double val;
  try {
    val = Double.valueOf(userInput);
  }
  catch(NumberFormatException e) {
    // Handle input format error
  }

  if(val >>= Double.MAX_VALUE - currentBalance) {
    // Handle range error
  }

  currentBalance += val;
}

...

Code Block
bgColor#ccccff
double currentBalance; // User's cash balance 

void doDeposit(String s){
  double val;
  try {
    val = Double.valueOf(userInput);
  }
  catch(NumberFormatException e) {
    // Handle input format error
  }

  if (Double.isInfinite(val)){
    // Handle infinity error 
  }

  if (Double.isNaN(val)) {
    // Handle NaN error 
  }

  if(val >>= Double.MAX_VALUE - currentBalance) {
    // Handle range error
  }
  currentBalance += val;
}

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

This rule appears in the C Secure Coding Standard as as FLP04-C. Check floating point inputs for exceptional values

...

FLP03-J. Use the strictfp modifier for floating point calculation consistency            07. Floating Point (FLP)            FLP30-J. Do not use floating point variables as loop counters