Examples of errors detected by the V1001 diagnostic


V1001. The variable is assigned but is not used by the end of the function.


EFL Core Libraries

V1001 The 'address_shadow' variable is assigned but is not used until the end of the function. elocation.c 1122


static Elocation_Address *address = NULL;

EAPI Eina_Bool
elocation_address_get(Elocation_Address *address_shadow)
{
   if (!address) return EINA_FALSE;
   if (address == address_shadow) return EINA_TRUE;

   address_shadow = address;
   return EINA_TRUE;
}

Most likely this is what should be written here: *address_shadow = *address;

Similar errors can be found in some other places:

  • V1001 The 'screen' variable is assigned but is not used until the end of the function. ecore_x_xinerama.c 92
  • V1001 The 'ret' variable is assigned but is not used until the end of the function. edje_edit.c 12774
  • V1001 The 'ret' variable is assigned but is not used until the end of the function. edje_edit.c 15884
  • And 2 additional diagnostic messages.

MuseScore

V1001 The 'ontime' variable is assigned but is not used until the end of the function. rendermidi.cpp 1176


bool renderNoteArticulation(....)
{
  int ontime    = 0;
  ....
  // render the suffix
  for (int j = 0; j < s; j++)
    ontime = makeEvent(suffix[j], ontime, tieForward(j,suffix));
  // render graceNotesAfter
  ontime = graceExtend(note->pitch(), ...., ontime);
  return true;
}

Skia Graphics Engine

V1001 CWE-563 The 'allDone' variable is assigned but is not used until the end of the function. skopcontour.cpp 40


SkOpSpan* SkOpContour::undoneSpan() {
  SkOpSegment* testSegment = &fHead;
  bool allDone = true;
  do {
    if (testSegment->done()) {
      continue;
    }
    allDone = false;
    return testSegment->undoneSpan();
  } while ((testSegment = testSegment->next()));
  if (allDone) {
    fDone = true;
  }
  return nullptr;
}

Very suspicious code, but it is difficult for me to understand what is the actual error here.


XNU kernel

V1001 CWE-563 The 'a' variable is assigned but is not used until the end of the function. sha1mod.c 120


__private_extern__ void
YSHA1Transform(u_int32_t state[5],
               const unsigned char buffer[64])
{
  u_int32_t a, b, c, d, e;
  ....
  state[0] += a;
  state[1] += b;
  state[2] += c;
  state[3] += d;
  state[4] += e;
  /* Wipe variables */
  a = b = c = d = e = 0;
}

The compiler can delete code "a = b = c = d = e = 0;" in terms of optimization.


Android

V1001 CWE-563 The 'a' variable is assigned but is not used until the end of the function. sha1.c 213


void SHA1Transform(uint32_t state[5], const uint8_t buffer[64])
{
  uint32_t a, b, c, d, e;
  ....
  /* Wipe variables */
  a = b = c = d = e = 0;
}

LibreOffice

V1001 The 'DL' variable is assigned but is not used by the end of the function. cipher.cxx 811


static void BF_updateECB(
    CipherContextBF    *ctx,
    rtlCipherDirection  direction,
    const sal_uInt8    *pData,
    sal_uInt8          *pBuffer,
    sal_Size            nLength)
{
    CipherKeyBF *key;
    sal_uInt32   DL, DR;

    key = &(ctx->m_key);
    if (direction == rtl_Cipher_DirectionEncode)
    {
        RTL_CIPHER_NTOHL64(pData, DL, DR, nLength);

        BF_encode(key, &DL, &DR);

        RTL_CIPHER_HTONL(DL, pBuffer);
        RTL_CIPHER_HTONL(DR, pBuffer);
    }
    else
    {
        RTL_CIPHER_NTOHL(pData, DL);
        RTL_CIPHER_NTOHL(pData, DR);

        BF_decode(key, &DL, &DR);

        RTL_CIPHER_HTONL64(DL, DR, pBuffer, nLength);
    }
    DL = DR = 0;
}

Similar errors can be found in some other places:

  • V1001 The 'DL' variable is assigned but is not used by the end of the function. cipher.cxx 860

Clang

V1001 [CWE-563] The 'Mode' variable is assigned but is not used by the end of the function. SIModeRegister.cpp 48


struct Status {
  unsigned Mask;
  unsigned Mode;

  Status() : Mask(0), Mode(0){};

  Status(unsigned Mask, unsigned Mode) : Mask(Mask), Mode(Mode) {
    Mode &= Mask;
  };
  ....
};

Clang

V1001 [CWE-563] The 'Size' variable is assigned but is not used by the end of the function. Object.cpp 424


class SectionBase {
  ....
  uint64_t Size = 0;
  ....
};

class SymbolTableSection : public SectionBase {
  ....
};

void SymbolTableSection::addSymbol(Twine Name, uint8_t Bind, uint8_t Type,
                                   SectionBase *DefinedIn, uint64_t Value,
                                   uint8_t Visibility, uint16_t Shndx,
                                   uint64_t Size) {
  ....
  Sym.Value = Value;
  Sym.Visibility = Visibility;
  Sym.Size = Size;
  Sym.Index = Symbols.size();
  Symbols.emplace_back(llvm::make_unique<Symbol>(Sym));
  Size += this->EntrySize;
}


Bugs Found

Checked Projects
344
Collected Errors
12 970