Examples of errors detected by the V627 diagnostic.


V627. Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number.


Samba

V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. regfio.c 1470


#define HBIN_HDR_SIZE    4

char header[HBIN_HDR_SIZE];

static REGF_HBIN* regf_hbin_allocate(REGF_FILE *file,
                                     uint32 block_size)
{
  REGF_HBIN *hbin;
  ....
  memcpy( hbin->header, "hbin", sizeof(HBIN_HDR_SIZE) );
  ....
}

It works. Good luck: sizeof(4) == 4.


Network Security Services (NSS)

V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. ssl3ext.c 1541


#define SSL3_MASTER_SECRET_LENGTH 48

SECStatus
ssl3_ServerHandleSessionTicketXtn(....)
{
  if (buffer_len < sizeof(SSL3_MASTER_SECRET_LENGTH))
    goto no_ticket;
  ....
}

Data Distribution Service

V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. test_position_independent_malloc.cpp 61


static void *
initialize (TEST_MALLOC *allocator)
{
  ....
  ACE_ALLOCATOR_RETURN (gap,
                        allocator->malloc (sizeof (256)),
                        0);
  ....
}

Similar errors can be found in some other places:

  • V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. malloc_test.cpp 168

WebRTC

V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. fsmdef.c 4481


#define CC_MAX_DIALSTRING_LEN (512)

static sm_rcs_t
fsmdef_ev_idle_feature (sm_event_t *event)
{
  ....
  memset(data->newcall.redirect.redirects[0].number, 0,
         sizeof(CC_MAX_DIALSTRING_LEN));
  ....
}

Similar errors can be found in some other places:

  • V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. fsmdef.c 4508
  • V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. fsmxfr.c 800
  • V627 Consider inspecting the expression. The argument of sizeof() is the macro which expands to a number. fsmxfr.c 1600


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;