Академический Документы
Профессиональный Документы
Культура Документы
memset
:
: 23.07.2012
,
.
, . Copy-Paste,
, unsigned_integer < 0. .
MAME, memset().
MAME - ,
,
[1]. ".c",
NAME ++.
110 .
MAME PVS-Studio , Windows
MinGW. MinGW GNU
Compiler Collection (GCC) Microsoft Windows [2]. , PVS-Studio
GCC .
MinGW PVS-Studio, 4.70. ,
.
MAME.
. , .
,
. , , .
. ,
, . ,
" ".
.
, MAME ,
memset. .
:
UINT32 m_pstars_regs[16];
static DRIVER_INIT( pstar )
{
...
memset(state->m_pstars_regs, 0, 16);
...
}
PVS-Studio: V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_pstars_regs'. pgm.c 4458
16 "m_pstars_regs". memset
. ,
.
:
memset(state->m_pstars_regs, 0, 16 * sizeof(UINT32));
. ,
(. [3]). .
.
, ? . 8 ,
:
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_kb_regs'.
pgm.c 4975
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_kb_regs'.
pgm.c 4996
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_kb_regs'.
pgm.c 5056
V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_oldsplus_ram'. pgm.c 5780
V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_oldsplus_regs'. pgm.c 5781
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_sysreg'.
rungun.c 399
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_ttl_vram'.
rungun.c 400
V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_playfield_code'. malzak.c 392
, .
. , . ,
.
UINT16
m_control_0[8];
#define ARRAY_LENGTH(x)
(sizeof(x) / sizeof(x[0]))
{
...
memset(state->m_control_0, 0,
ARRAY_LENGTH(state->m_control_0));
}
PVS-Studio: V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_control_0'. tumbleb.c 2065
ARRAY_LENGTH.
. , .
.
:
memset(state->m_control_0, 0, sizeof(state->m_control_0));
:
memset(state->m_control_0, 0,
ARRAY_LENGTH(state->m_control_0) * sizeof(UINT16));
, :
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_pmac_read'.
megadriv.c 7156
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_pmac_write'.
megadriv.c 7157
V512 A call of the 'memset' function will lead to underflow of the buffer 'state>m_cart_is_genesis'. megatech.c 426
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_vol_ctrl'.
nycaptor.c 841
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_rotate_ctrl'.
wgp.c 949
V512 A call of the 'memset' function will lead to underflow of the buffer 'state->m_vreg'.
othldrby.c 237
memset() . ,
. memcpy().
memcpy()
, :
#define CHD_SHA1_BYTES
20
#define CHD_V4_HEADER_SIZE
#define CHD_MAX_HEADER_SIZE
108
CHD_V4_HEADER_SIZE
memset() . ,
memcpy() , -
. :
UINT16 m_spriteram16[0x1000];
UINT16 m_spriteram16_buffered[0x1000];
PVS-Studio: V512 A call of the 'memcpy' function will lead to underflow of the buffer 'state>m_spriteram16_buffered'. deco32.c 706
. . , ,
sizeof(UINT16).
:
memcpy(state->m_spriteram16_buffered,
state->m_spriteram16,
0x1000 * sizeof(UINT16));
:
V512 A call of the 'memcpy' function will lead to underflow of the buffer 'state>m_spriteram16_2_buffered'. deco32.c 726
Copy-Paste
, -
Copy-Paste. - , - . MAME
, - . .
static WRITE8_HANDLER( tms70x0_pf_w )
{
...
if( ((cpustate->pf[0x03] & 0x80) == 0) &&
((data & 0x80) == 0x80 ) )
{
...
}
else if( ((data & 0x80) == 0x80 ) &&
((cpustate->pf[0x03] & 0x80) == 0) )
{
...
}
...
}
PVS-Studio: V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of
logical error presence. Check lines: 577, 584. tms7000.c 577
, , .
, .
.
class device_debug
{
device_disasm_interface *m_disasm;
...
int min_opcode_bytes() const
{
return (m_disasm != NULL) ?
m_disasm->max_opcode_bytes() : 1;
}
int max_opcode_bytes() const
{
return (m_disasm != NULL) ?
m_disasm->max_opcode_bytes() : 1;
}
}
PVS-Studio: V524 It is odd that the body of 'max_opcode_bytes' function is fully equivalent to the body
of 'min_opcode_bytes' function (debugcpu.h, line 150). debugcpu.h 151
max_opcode_bytes() min_opcode_bytes().
. , min_opcode_bytes() :
int min_opcode_bytes() const
{
return (m_disasm != NULL) ?
m_disasm->min_opcode_bytes() : 1;
}
, :
V583 The '?:' operator, regardless of its conditional expression, always returns one and the same
value: ",(%d,". 9900dasm.c 670
V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical
error presence. Check lines: 549, 579. cdrom.c 549
V501 There are identical sub-expressions 'offset != (0x370 >> 1)' to the left and to the right of
the '&&' operator. decoprot.c 118
V501 There are identical sub-expressions 'offset != (0x3c0 >> 1)' to the left and to the right of
the '&&' operator. decoprot.c 118
V501 There are identical sub-expressions 'offset != 0x2c / 2' to the left and to the right of the
'&&' operator. decoprot.c 240
V501 There are identical sub-expressions 'offset != 0xe' to the left and to the right of the '&&'
operator. decoprot.c 447
Undefined behavior
, PVS-Studio, .
undefined behavior. , ,
.
. , ,
. : " ,
. ." [4].
, . :
#define ATARIRLE_PRIORITY_SHIFT
12
#define ATARIRLE_PRIORITY_MASK \
((~0 << ATARIRLE_PRIORITY_SHIFT) & 0xffff)
PVS-Studio: V610 Undefined behavior. Check the shift operator '<<. The left operand '~0' is negative.
atarig42.c 220
, ATARIRLE_PRIORITY_MASK
. .
:
#define ATARIRLE_PRIORITY_MASK \
((~(0u) << ATARIRLE_PRIORITY_SHIFT) & 0xffff)
, :
UINT32 m_color1_mask;
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
PALETTE_INIT( montecar )
{
memset() memcpy(), memcmp(). .
MAME , .
static const char *apr_magic = "ACT Apricot disk image\x1a\x04";
FLOPPY_IDENTIFY( apridisk_identify )
{
UINT8 header[APR_HEADER_SIZE];
floppy_image_read(floppy, &header, 0, sizeof(header));
if (memcmp(header, apr_magic, sizeof(apr_magic)) == 0)
...
}
PVS-Studio: V579 The memcmp function receives the pointer and its size as arguments. It is possibly a
mistake. Inspect the third argument. apridisk.c 128
sizeof() , . ,
. ,
'apr_magic' :
static const char apr_magic[] = "ACT Apricot disk image\x1a\x04";
, :
int m_led_extender;
#define CARD_A
#define NO_EXTENDER
. .
V595, . ,
. :
static void stv_vdp2_drawgfxzoom(...,
const gfx_element *gfx, ...)
{
...
if (gfx->pen_usage &&
transparency == STV_TRANSPARENCY_PEN)
{
...
}
if( gfx )
{
...
}
...
}
PVS-Studio: V595 The 'gfx' pointer was utilized before it was verified against nullptr. Check lines: 2457,
2483. stvvdp2.c 2457
, ,
. , Copy-Paste. ,
. :
static DEVICE_START( deco16ic )
{
...
if (intf->split)
deco16ic->pf2_tilemap_16x16 =
tilemap_create_device(device, get_pf2_tile_info,
deco16_scan_rows, 16, 16, fullwidth ?
, , , ,
MAME PVS-Studio. , PVS-Studio
. make-,
. ,
, MinGW.
P.S. Visual Studio,
. . ,
,
, Visual Studio.
1. Wikipedia. MAME. http://www.viva64.com/go.php?url=842
2. Wikipedia. MinGW. http://www.viva64.com/go.php?url=892
3. .
. http://www.viva64.com/ru/b/0116/
4. , . . http://www.viva64.com/ru/b/0142/