Примеры ошибок, обнаруженных с помощью диагностики V511
V511. The sizeof() operator returns pointer size instead of array size.
Shareaza
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ( arrChar )' expression. BugTrap encoding.cpp 477
#define countof(array) (sizeof(array) / sizeof((array)[0]))
size_t AnsiDecodeChar(const BYTE* pBytes,
size_t nNumBytes, TCHAR arrChar[2],
size_t& nCharSize)
{
....
nCharSize = MultiByteToWideChar(CP_ACP, 0,
(const CHAR*)pBytes, nNumBytesInChar,
arrChar, countof(arrChar));
....
}
The B object is simply a pointer. Value 2 in the square brackets indicates to the programmer that he is working with an array of 2 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(arrChar) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Wolfenstein 3D
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (src)' expression. Splines math_matrix.h 94
ID_INLINE mat3_t::mat3_t( float src[ 3 ][ 3 ] ) {
memcpy( mat, src, sizeof( src ) );
}
The 'src' object is simply a pointer. Value 3x3 in the square brackets indicates to the programmer that he is working with an array of 3x3 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(src) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Wolfenstein 3D
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (result)' expression. cgame bg_animation.c 807
void BG_ParseConditionBits(
char **text_pp, animStringItem_t *stringTable,
int condIndex, int result[2] )
{
....
memset( result, 0, sizeof( result ) );
....
}
The 'result' object is simply a pointer. Value 2 in the square brackets indicates to the programmer that he is working with an array of 2 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(result) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Chromium
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (salt)' expression. browser visitedlink_master.cc 968
uint8 salt_[LINK_SALT_LENGTH];
VisitedLinkMaster::TableBuilder::TableBuilder(
VisitedLinkMaster* master,
const uint8 salt[LINK_SALT_LENGTH])
: master_(master),
success_(true) {
fingerprints_.reserve(4096);
memcpy(salt_, salt, sizeof(salt));
}
The 'salt' object is simply a pointer. Value LINK_SALT_LENGTH in the square brackets indicates to the programmer that he is working with an array of LINK_SALT_LENGTH items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(salt) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Similar errors can be found in some other places:
- V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (salt)' expression. common visitedlink_common.cc 84
MySQL
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (buf)' expression. auth_win_client common.cc 489
typedef char Error_message_buf[1024];
const char* get_last_error_message(Error_message_buf buf)
{
int error= GetLastError();
buf[0]= '\0';
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)buf, sizeof(buf), NULL );
return buf;
}
The 'buf' object is simply a pointer. So, the sizeof(buf) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Intel AMT SDK
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (pid)' expression. PskGenerator pskgenerator.cpp 126
typedef char PID[pid_len+1];
typedef char PPS[pps_len+1];
static void generate(PID pid, PPS pps)
{
memset(pid,0,sizeof(pid));
memset(pps,0,sizeof(pps));
....
}
The 'pid/pps' object is simply a pointer. Value pid_len+1 / pps_len+1 in the square brackets indicates to the programmer that he is working with an array of N items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(pid) / sizeof(pps) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
Similar errors can be found in some other places:
- V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (pps)' expression. PskGenerator pskgenerator.cpp 127
ReactOS
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (dest)' expression. glu32 mapdesc.cc 95
void
Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] )
{
memset( dest, 0, sizeof( dest ) );
for( int i=0; i != hcoords; i++ )
dest[i][i] = 1.0;
}
The 'dest' object is simply a pointer. Value [MAXCOORDS][MAXCOORDS] in the square brackets indicates to the programmer that he is working with an array of MAXCOORDS x MAXCOORDS items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(dest) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system). This is what should have been written here: Mapdesc::identify( REAL (&dest)[MAXCOORDS][MAXCOORDS] )
Samba
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((domain))' expression. wbinfo.c 124
#define FSTRING_LEN 256
typedef char fstring[FSTRING_LEN];
char *safe_strcpy(char *dest,const char *src, size_t maxlength)
#define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
static bool parse_wbinfo_domain_user(
const char *domuser, fstring domain, fstring user)
{
....
/* Maybe it was a UPN? */
if ((p = strchr(domuser, '@')) != NULL) {
fstrcpy(domain, "");
fstrcpy(user, domuser);
return true;
}
....
}
Similar errors can be found in some other places:
- V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((user))' expression. wbinfo.c 125
- V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((user))' expression. wbinfo.c 129
- V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((domain))' expression. wbinfo.c 130
- And 22 additional diagnostic messages.
Source Engine SDK
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (iNeighbors)' expression. Vrad_dll disp_vrad.cpp 60
#define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
#define _ARRAYSIZE(A) RTL_NUMBER_OF_V1(A)
int GetAllNeighbors( const CCoreDispInfo *pDisp,
int iNeighbors[512] )
{
....
if ( nNeighbors < _ARRAYSIZE( iNeighbors ) )
iNeighbors[nNeighbors++] = pCorner->m_Neighbors[i];
....
}
Oracle VM Virtual Box
V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (plane)' expression. devvga-svga3d-win.cpp 4650
int vmsvga3dSetClipPlane(...., float plane[4]) // <=
{
....
/* Store for vm state save/restore. */
pContext->state.aClipPlane[index].fValid = true;
memcpy(pContext->state.aClipPlane[....], plane, sizeof(plane));
....
}