Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Examples of errors detected by the V561…

Examples of errors detected by the V561 diagnostic

V561. Consider assigning value to 'foo' variable instead of declaring it anew.


FCEUX

V561 It's probably better to assign value to 'x' variable than to declare it anew. Previous daclaration: ines.cpp, line 960. fceux ines.cpp 962


int iNesSaveAs(char* name)
{
  ....
  fp = fopen(name,"wb");
  int x = 0;
  if (!fp)
    int x = 1;
  ....
}

Vscap

V561 It's probably better to assign value to 'ret' variable than to declare it anew. Previous daclaration: TransparentWnd.cpp, line 1802. vscap transparentwnd.cpp 1804


BOOL CTransparentWnd::SaveShape(FILE* fptr)
{
  ....
  BOOL ret = TRUE;
  if (m_hbitmap)
    BOOL ret = picture.SaveToFile(fptr);
  ....
}

FlightGear

V561 It's probably better to assign value to 's' variable than to declare it anew. Previous declaration: dclgps.cxx, line 480. dclgps.cxx 485


void DCLGPS::update(double dt) {
  ....
  string s;
  if(fgGetBool("/instrumentation/nav[0]/slaved-to-gps")) {
    // TODO - avoid the hardwiring on nav[0]
    s = "Adj Nav Crs to ";
  } else {
    string s = "GPS Course is ";
  }
  ....
}

Unreal Engine 4

V561 It's probably better to assign value to 'Existing' variable than to declare it anew. Previous declaration: streamablemanager.cpp, line 325. streamablemanager.cpp 332


void FStreamableManager::AsyncLoadCallback(
  FStringAssetReference Request)
{
  ....
  FStreamable* Existing = StreamableItems.FindRef(TargetName);
  ....
  if (!Existing)
  {
    // hmm, maybe it was redirected by a consolidate
    TargetName = ResolveRedirects(TargetName);
    FStreamable* Existing = StreamableItems.FindRef(TargetName);
  }
  if (Existing && Existing->bAsyncLoadRequestOutstanding)
  ....
}

This is what should have been written here: Existing = StreamableItems.FindRef(TargetName);


Oracle VM Virtual Box

V561 It's probably better to assign value to 'Status' variable than to declare it anew. Previous declaration: vboxmpwddm.cpp, line 5723. vboxmpwddm.cpp 5728


static NTSTATUS APIENTRY
DxgkDdiRenderNew(CONST HANDLE hContext, DXGKARG_RENDER  *pRender)
{
  ....
  NTSTATUS Status = STATUS_SUCCESS;    // <=

  __try
  {
    ....
    NTSTATUS Status = STATUS_SUCCESS;  // <=
    ....
  }
  __except (EXCEPTION_EXECUTE_HANDLER)
  {
    Status = STATUS_INVALID_PARAMETER;
    WARN(("invalid parameter"));
  }

  return Status;
}

Any change of the variable within the try..except section won't change the returned value and the external (in relation to the try {} block) variable will be changed only if an exception occurs.


Godot Engine

V561 It's probably better to assign value to 'styles_count' variable than to declare it anew. Previous declaration: export.cpp, line 610. export.cpp 633


void EditorExportPlatformAndroid::_fix_manifest(....)
{
  ....
  uint32_t string_count;
  uint32_t styles_count;
  uint32_t string_flags;
  uint32_t string_data_offset;
  ....
  switch(chunk)
  {
    case CHUNK_STRINGS:
    {
      int iofs=ofs+8;
      uint32_t string_count=decode_uint32(....);
      uint32_t styles_count=decode_uint32(....);
      uint32_t string_flags=decode_uint32(....);
      uint32_t string_data_offset=decode_uint32(....);
      uint32_t styles_offset=decode_uint32(....);
      ....
    }
    ....
  }
  ....
}

Godot Engine

V561 It's probably better to assign value to 'all_const' variable than to declare it anew. Previous declaration: shader_language.cpp, line 1225. shader_language.cpp 1274


ShaderLanguage::Node*
ShaderLanguage::validate_function_call(....)
{
  ....
  bool all_const=true;
  ....
  if (p_func->op==OP_CONSTRUCT && all_const)
  {
    bool all_const=false;
    ....
  }
  ....
}

Telegram

V561 It's probably better to assign value to 'assocHandlers' variable than to declare it anew. Previous declaration: pspecific_wnd.cpp, line 2031. Telegram pspecific_wnd.cpp 2107


bool psShowOpenWithMenu(....)
{
  ....
  IEnumAssocHandlers *assocHandlers = 0;
  ....
  if (....)
  {
    ....
    IEnumAssocHandlers *assocHandlers = 0;
    ....
  }
  ....
}

Similar errors can be found in some other places:

  • V561 It's probably better to assign value to 'ms' variable than to declare it anew. Previous declaration: window.cpp, line 1371. Telegram window.cpp 1467

Firebird

V561 It's probably better to assign value to 'exit_code' variable than to declare it anew. Previous declaration: svc.cpp, line 1893. svc.cpp 1898


THREAD_ENTRY_DECLARE Service::run(THREAD_ENTRY_PARAM arg)
{
  int exit_code = -1;
  try
  {
    Service* svc = (Service*)arg;
    RefPtr<SvcMutex> ref(svc->svc_existence);
    int exit_code = svc->svc_service_run->serv_thd(svc);

    svc->started();
    svc->svc_sem_full.release();
    svc->finish(SVC_finished);
  }
  catch (const Exception& ex)
  {
    // Not much we can do here
    iscLogException("Exception in Service::run():", ex);
  }

  return (THREAD_ENTRY_RETURN)(IPTR) exit_code;
}

OpenJDK

V561 It's probably better to assign value to 'maybe_null' variable than to declare it anew. Previous declaration: graphKit.cpp, line 2170. graphKit.cpp 2175


Node* GraphKit::record_profiled_receiver_for_speculation(Node* n)
{
  ....
  ciKlass* exact_kls = profile_has_unique_klass();
  bool maybe_null = true;
  if (java_bc() == Bytecodes::_checkcast ||
      java_bc() == Bytecodes::_instanceof ||
      java_bc() == Bytecodes::_aastore) {
    ciProfileData* data =
      method()->method_data()->bci_to_data(bci());
    bool maybe_null = data == NULL ? true :    // <=
                      data->as_BitData()->null_seen();
  }
  return record_profile_for_speculation(n,
    exact_kls, maybe_null);
  return n;
}

Chromium

V561 CWE-563 It's probably better to assign value to 'signin_scoped_device_id' variable than to declare it anew. Previous declaration: profile_sync_service.cc, line 900. profile_sync_service.cc 906


void ProfileSyncService::OnEngineInitialized(....)
{
  ....
  std::string signin_scoped_device_id;
  if (IsLocalSyncEnabled()) {
    signin_scoped_device_id = "local_device";
  } else {
    SigninClient* signin_client = ....;
    DCHECK(signin_client);
    std::string signin_scoped_device_id =                 // <=
        signin_client->GetSigninScopedDeviceId();
  }
  ....
}

A new variable signin_scoped_device_id shouldn't be declared, an existing one should be used.


Amazon Lumberyard

V561 CWE-563 It's probably better to assign value to 'pLibrary' variable than to declare it anew. Previous declaration: entityobject.cpp, line 4703. entityobject.cpp 4706


void CEntityObject::OnMenuConvertToPrefab()
{
  ....
  IDataBaseLibrary* pLibrary = GetIEditor()->Get....;
  if (pLibrary == NULL)
  {
    IDataBaseLibrary* pLibrary = GetIEditor()->Get....;
  }

  if (pLibrary == NULL)
  {
    QString sError = tr(....);
    CryMessageBox(....);
    return;
  }
  ....
}

Similar errors can be found in some other places:

  • V561 CWE-563 It's probably better to assign value to 'eType' variable than to declare it anew. Previous declaration: toglsloperand.c, line 838. toglsloperand.c 1224
  • V561 CWE-563 It's probably better to assign value to 'eType' variable than to declare it anew. Previous declaration: toglsloperand.c, line 838. toglsloperand.c 1305
  • V561 CWE-563 It's probably better to assign value to 'rSkelPose' variable than to declare it anew. Previous declaration: attachmentmanager.cpp, line 409. attachmentmanager.cpp 458
  • And 8 additional diagnostic messages.

NCBI Genome Workbench

V561 It's probably better to assign value to 'seq' variable than to declare it anew. Previous declaration: validator.cpp, line 490. validator.cpp 492


bool CValidator::IsSeqLocCorrectlyOrdered(const CSeq_loc& loc, CScope& scope)
{
  CBioseq_Handle seq;
  try {
    CBioseq_Handle seq = scope.GetBioseqHandle(loc);
  } catch (CObjMgrException& ) {
    // no way to tell
    return true;
  } catch (const exception& ) {
    // no way to tell
    return true;
  }
  if (seq  &&  seq.GetInst_Topology() == CSeq_inst::eTopology_circular) {
    // no way to check if topology is circular
    return true;
  }

  return CheckConsecutiveIntervals(loc, scope, x_IsCorrectlyOrdered);
}

Qt

V561 [CWE-563] It's probably better to assign value to 'selectedPhraseBook' variable than to declare it anew. Previous declaration: mainwindow.cpp, line 1303. mainwindow.cpp 1313


void MainWindow::addToPhraseBook()
{
  ....
  QString selectedPhraseBook;
  if (phraseBookList.size() == 1) {
    selectedPhraseBook = phraseBookList.at(0);
    if (QMessageBox::information(this, tr("Add to phrase book"),
          tr("Adding entry to phrasebook %1").arg(selectedPhraseBook),
           QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok)
                          != QMessageBox::Ok)
      return;
  } else {
    bool okPressed = false;
    QString selectedPhraseBook =
      QInputDialog::getItem(this, tr("Add to phrase book"),
                            tr("Select phrase book to add to"),
                            phraseBookList, 0, false, &okPressed);
    if (!okPressed)
      return;
  }

  MessageItem *currentMessage = m_dataModel->messageItem(m_currentIndex);
  Phrase *phrase = new Phrase(currentMessage->text(),
                              currentMessage->translation(),
                              QString(), nullptr);

  phraseBookHash.value(selectedPhraseBook)->append(phrase);
}

Overgrowth

V561 [CERT-DCL01-C] It's probably better to assign value to 'other_radius_sq' variable than to declare it anew. Previous declaration: scenegraph.cpp, line 2006. scenegraph.cpp 2010


bool SceneGraph::AddDynamicDecal(....)
{
  ....
  float other_radius_sq = ....;
  if(....)
  {
    ....
    float other_radius_sq = ....;
  }
  ....
}

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