Examples of errors detected by the V609 diagnostic.


V609. Divide or mod by zero.


VNL

V609 Divide by zero. Denominator 'x' == 0. pow_ii.c 28


integer pow_ii(integer *ap, integer *bp)
{
  integer pow, x, n;
  unsigned long u;

  x = *ap;
  n = *bp;

  if (n <= 0)
  {
    if (n == 0 || x == 1)
      return 1;

    if (x != -1)
      return x == 0 ? 1/x : 0;

    n = -n;
  }
  ....
}

Mozilla Thunderbird

V609 Divide by zero. Denominator range [0..8]. ionbuilder.cpp 10922


static inline size_t UnboxedTypeSize(JSValueType type)
{
  switch (type) {
    ....
  default: return 0;
  }
}

MInstruction*IonBuilder::loadUnboxedProperty(size_t offset,
                              JSValueType unboxedType, ....)
{
  size_t index = offset / UnboxedTypeSize(unboxedType);
  ....
}

Similar errors can be found in some other places:

  • V609 Divide by zero. Denominator range [0..8]. ionbuilder.cpp 11844

Inkscape

V609 Divide by zero. Denominator range [0..999]. lpe-fillet-chamfer.cpp 607


Geom::PathVector
LPEFilletChamfer::doEffect_path(....)
{
  ....
  if(....){
    ....
  } else if (type >= 3000 && type < 4000) {
      unsigned int chamferSubs = type-3000;
      ....
      double chamfer_stepsTime = 1.0/chamferSubs;
      ....
  }
  ....
}

Similar errors can be found in some other places:

  • V609 Divide by zero. Denominator range [0..999]. lpe-fillet-chamfer.cpp 623

Chromium

V609 Divide by zero. Denominator range [0..4096]. addr.h 159


static int BlockSizeForFileType(FileType file_type) {
    switch (file_type) {
      ....
      default:
        return 0;
    }
}

static int RequiredBlocks(int size, FileType file_type)
{
  int block_size = BlockSizeForFileType(file_type);
  return (size + block_size - 1) / block_size;             // <=
}

EFL Core Libraries

V609 Mod by zero. Denominator range [0..24]. eina_inline_value_util.x 59


static inline size_t
eina_value_util_type_size(const Eina_Value_Type *type)
{
  if (type == EINA_VALUE_TYPE_INT)
    return sizeof(int32_t);
  if (type == EINA_VALUE_TYPE_UCHAR)
    return sizeof(unsigned char);
  if ((type == EINA_VALUE_TYPE_STRING) ||
      (type == EINA_VALUE_TYPE_STRINGSHARE))
    return sizeof(char*);
  if (type == EINA_VALUE_TYPE_TIMESTAMP)
    return sizeof(time_t);
  if (type == EINA_VALUE_TYPE_ARRAY)
    return sizeof(Eina_Value_Array);
  if (type == EINA_VALUE_TYPE_DOUBLE)
    return sizeof(double);
  if (type == EINA_VALUE_TYPE_STRUCT)
    return sizeof(Eina_Value_Struct);
  return 0;                                            // <=
}

static inline unsigned int
eina_value_util_type_offset(
  const Eina_Value_Type *type, unsigned int base)
{
   unsigned size, padding;
   size = eina_value_util_type_size(type);             // <=
   if (!(base % size))                                 // <=
     return base;
   padding = ( (base > size) ? (base - size) : (size - base));
   return base + padding;
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
We use cookies for the analysis of events to improve our content and make user interaction more convenient. By continuing the view of our web-pages you accept the terms of using these files. You can find out more about cookie-files and privacy policy or close the notification, by clicking on the button. Learn More →
Do not show again