Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: C++ semantics - 06.11

>
>
>
Examples of errors detected by the V601…

Examples of errors detected by the V601 diagnostic

V601. Suspicious implicit type casting.


IPP Samples

V601 The 'false' value becomes a class object. me umc_vec_prediction.cpp 754


class MeMV
{
public:
  MeMV(){};
  MeMV(int a0){x = (Ipp16s)a0; y=(Ipp16s)a0;};
  MeMV(int a0, int a1){x = (Ipp16s)a0; y=(Ipp16s)a1;};
  ....
}

MeMV MePredictCalculatorVC1::GetPrediction8x8()
{
  ....
  default:
    return false;
  ....
}

Similar errors can be found in some other places:

  • V601 The 'false' value becomes a class object. me umc_vec_prediction.cpp 717

WebPagetest

V601 The bool type is implicitly cast to the integer type. Inspect the first argument. web_browser.cc 548


HANDLE WebBrowser::FindAdditionalHookProcess(
  HANDLE launched_process, CString exe)
{
  ....
  CString exe(proc.szExeFile);
  exe.MakeLower();
  if (exe.Find(_T("webkit2webprocess.exe") >= 0)) {
  ....
}

This is what should have been written here: if (exe.Find(_T("webkit2webprocess.exe")) >= 0)


WebPagetest

V601 The bool type is implicitly cast to the integer type. Inspect the first argument. web_browser.cc 429


bool WebBrowser::FindBrowserChild(
  DWORD pid, PROCESS_INFORMATION& pi,
  LPCTSTR browser_exe)
{
  ....
  CString exe(proc.szExeFile);
  exe.MakeLower();
  if (exe.Find(browser_exe >= 0)) {
  ....
}

This is what should have been written here: if (exe.Find(browser_exe) >= 0)


Micro-Manager

V601 The 'false' value is implicitly cast to the integer type. Property.cpp 364


#define DEVICE_OK   0
#define DEVICE_ERR  1 // generic, undefined error
#define DEVICE_INVALID_PROPERTY  2

int MM::PropertyCollection::CreateProperty(....)
{
  if (Find(pszName))
    return DEVICE_DUPLICATE_PROPERTY;
  ....
  if (!pProp->Set(pszValue))
    return false;
  ....
  return DEVICE_OK;
}

Micro-Manager

V601 The 'true' value is implicitly cast to the integer type. Property.cpp 464


#define DEVICE_OK   0
#define DEVICE_ERR  1 // generic, undefined error
#define DEVICE_INVALID_PROPERTY  2

int MM::PropertyCollection::RegisterAction(
  const char* pszName, MM::ActionFunctor* fpAct)
{
  MM::Property* pProp = Find(pszName);
  if (!pProp)
    return DEVICE_INVALID_PROPERTY;
  pProp->RegisterAction(fpAct);
  return true;
}

Similar errors can be found in some other places:

  • V601 The 'false' value is implicitly cast to the integer type. PIGCSControllerCom.cpp 405
  • V601 The 'false' value is implicitly cast to the integer type. Prior.cpp 778
  • V601 The 'false' value is implicitly cast to the integer type. Prior.cpp 2308
  • And 8 additional diagnostic messages.

Doxygen

V601 The bool type is implicitly cast to the class type. Inspect the fifth argument. context.cpp 1712


static MemberListInfoContext *alloc(Definition *def,
                          const QCString &relPath,
                          const MemberList *ml,
                          const QCString &title,
                          const QCString &subtitle=QCString())
{ return new MemberListInfoContext(def,relPath,
                                     ml,title,subtitle); }

TemplateVariant getMemberList(
                         SharedPtr<MemberListInfoContext> &list,
                         MemberListType type,
                         const char *title,
                         bool detailed=FALSE) const
{
  ....
  MemberList *ml = m_classDef->getMemberList(type);
  ....
  list.reset(MemberListInfoContext::alloc(m_classDef,
                        relPathAsString(),ml,title,detailed));
  ....
}

Similar errors can be found in some other places:

  • V601 The bool type is implicitly cast to the class type. Inspect the fifth argument. context.cpp 2315
  • V601 The bool type is implicitly cast to the class type. Inspect the fifth argument. context.cpp 2675
  • V601 The bool type is implicitly cast to the class type. Inspect the fifth argument. context.cpp 4456

Doxygen

V601 The bool type is implicitly cast to the class type. docsets.cpp 473


struct IncludeInfo
{
  ....
  bool local;
};

void DocSets::addIndexItem(Definition *context,MemberDef *md,
                           const char *,const char *)
{
  QCString decl;
  ....
  IncludeInfo *ii = cd->includeInfo();
  ....
  decl=ii->local;
  ....
}

Firebird

V601 The string literal is implicitly cast to the bool type. Inspect the second argument. backup.cpp 6113


int put_message(....)
{
  if (newlen <= MAX_UCHAR)
  {
    put(tdgbl, attribute);
    put(tdgbl, (UCHAR) newlen);
  }
  else if (newlen <= MAX_USHORT)
  {
    if (!attribute2)
      BURP_error(314, "");
    ....
  }
  else
    BURP_error(315, "");
  ....
}

Similar errors can be found in some other places:

  • V601 The string literal is implicitly cast to the bool type. Inspect the second argument. backup.cpp 6120

Notepad++

V601 The 'false' value becomes a class object. treeview.cpp 121


typedef std::basic_string<TCHAR> generic_string;

generic_string TreeView::getItemDisplayName(....) const
{
  if (not Item2Set)
    return false;                     // <=
  TCHAR textBuffer[MAX_PATH];
  TVITEM tvItem;
  tvItem.hItem = Item2Set;
  tvItem.mask = TVIF_TEXT;
  tvItem.pszText = textBuffer;
  tvItem.cchTextMax = MAX_PATH;
  SendMessage(...., reinterpret_cast<LPARAM>(&tvItem));
  return tvItem.pszText;
}

SCIM

V601 The 'true' value is implicitly cast to the integer type. scim_anthy_style_file.cpp 204


static int get_value_position (String &str)           // <=
{
  ....
  if (spos >= str.length ())
    return true;                                      // <=
  else
    spos++;
  for (;
       spos < str.length () && isspace(str[spos]);
       spos++);

  return spos;
}

Rosegarden

V601 The integer type is implicitly cast to the char type. MidiEvent.cpp 181


QDebug &
operator<<(QDebug &dbg, const MidiEvent &midiEvent)
{
  timeT tempo;
  int tonality;
  std::string sharpflat;
  ....
  tonality = (int)midiEvent.m_metaMessage[0];

  if (tonality < 0) {
    sharpflat = -tonality + " flat"; // <=
  } else {
    sharpflat = tonality;            // <=
    sharpflat += " sharp";
  }
  ....
}

Rosegarden

V601 The string literal is implicitly cast to the bool type. FileSource.cpp 902


bool
FileSource::createCacheFile()
{
  {
    QMutexLocker locker(&m_mapMutex);

#ifdef DEBUG_FILE_SOURCE
    std::cerr << "...." << m_refCountMap[m_url] << std::endl;
#endif

    if (m_refCountMap[m_url] > 0) {
      m_refCountMap[m_url]++;
      m_localFilename = m_remoteLocalMap[m_url];
#ifdef DEBUG_FILE_SOURCE
      std::cerr << "...." << m_refCountMap[m_url] << std::endl;
#endif
      m_refCounted = true;
      return true;
    }
  }

  QDir dir;
  try {
      dir = TempDirectory::getInstance()->....;
  } catch (DirectoryCreationFailed f) {
#ifdef DEBUG_FILE_SOURCE
      std::cerr << "...." << f.what() << std::endl;
#endif
      return "";  // <=
  }
  ....
}

TON

V601 The 'false' value is implicitly cast to the integer type. mc-config.cpp 884


static int process_workchain_shard_hashes(....) {
  ....
  if (f == 1) {
    if ((shard.shard & 1) || cs.size_ext() != 0x20000) {
      return false;                                     // <=
    }
    ....
    int r = process_workchain_shard_hashes(....);
    if (r < 0) {
      return r;
    }
    ....
    return cb.store_bool_bool(true) && cb.store_ref_bool(std::move(left)) &&
            cb.store_ref_bool(std::move(right)) &&
            cb.finalize_to(branch)
               ? r
               : -1;
  ....
}

VVVVVV

V601 The integer type is implicitly cast to the char type. Game.cpp 4997


//Some stats:
int totalflips;
std::string hardestroom;
int hardestroomdeaths;

void Game::loadquick(....)
{
  ....

  else if (pKey == "totalflips")
  {
      totalflips = atoi(pText);
  }
  else if (pKey == "hardestroom")
  {
      hardestroom = atoi(pText);        // <=
  }
  else if (pKey == "hardestroomdeaths")
  {
      hardestroomdeaths = atoi(pText);
  }

  ....
}

Dlib

V601 The bool type is implicitly cast to the double type. console_progress_indicator.h 136


class console_progress_indicator
{
  ....
  double seen_first_val;
  ....
};

bool console_progress_indicator::
print_status (
  double cur,
  bool always_print
)
{
  ....
  if (!seen_first_val)
  {
    start_time = cur_time;
    last_time = cur_time;
    first_val = cur;
    seen_first_val = true;  // <=
    return false;
  }
  ....
}

qdEngine

V601 [CWE-704, CERT-INT36-C] The 'false' value is implicitly cast to the pointer. qd_interface_dispatcher.cpp 772


const char* qdInterfaceDispatcher::get_save_title() const
{
  if(!cur_screen_)
    return false;
  ....
  return false;
}

Similar errors can be found in some other places:

  • V601 [CWE-704, CERT-INT36-C] The 'false' value is implicitly cast to the pointer. qd_interface_dispatcher.cpp 783

PPSSPP

V601 The bool type is implicitly cast to the float type. Inspect the first argument. ControlMappingScreen.cpp 810


MockButton *SetFlipHBG(float f);
....
MockPSP::MockPSP(UI::LayoutParams *layoutParams) : AnchorLayout(layoutParams)
{
  ....
  AddButton(CTRL_RTRIGGER,
            ImageID("I_R"),
            ImageID("I_SHOULDER_LINE"),
            0.0f,
            LayoutSize(50.0f, 16.0f, 397.0f, 0.0f))->SetFlipHBG(true);  // <=
  ....
}