Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed stupid example

...

Noncompliant Code Example

This noncompliant code example can result in a divide-by-zero error during the division of the signed operands s_a and s_bFurthermore, this code allows overflow to occur in the division operation; see INT32-C. Ensure that operations on signed integers do not result in overflow for more information.

Code Block
bgColor#FFcccc
langc
#include <limits.h>
 
void func(signed long s_a, signed long s_b) {
  signed long result;
  result = s_a / s_b;
  /* ... */
}

Noncompliant Code Example

This noncompliant code example can result in a divide-by-zero error during the division of the signed operands s_a and s_b. 

Code Block
bgColor#FFcccc
langc
#include <limits.h>
 
void func(signed long s_a, signed long s_b) {
  signed long result;
  if ((s_a == LONG_MIN) && (s_b == -1)) {
    /* Handle error */
  } else {
    result = s_a / s_b;
  }
  /* ... */
}

...

The remainder operator provides the remainder when two operands of integer type are divided. 

Noncompliant Code Example

This noncompliant code example can result in a divide-by-zero error during the modulo operation on the signed operands s_a and s_b.

...