Remove casts of malloc result; add notes on unchecked malloc result

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1530 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Rutger Hofman 16 years ago
parent fe5e343529
commit 69f787a86b

@ -256,14 +256,14 @@ urj_bsdl_set_path (urj_chain_t *chain, const char *pathlist)
{
num++;
/* extend path list array */
globs->path_list =
(char **) realloc (globs->path_list,
(num + 1) * sizeof (char *));
globs->path_list = realloc (globs->path_list,
(num + 1) * sizeof (char *));
/* enter path element up to the delimeter */
if (delim == NULL)
len = strlen (elem);
else
len = delim - elem;
/* @@@@ ToDo check malloc result RFHH */
pathelem = malloc (len + 1);
memcpy (pathelem, elem, len);
pathelem[len] = '\0';
@ -324,8 +324,9 @@ urj_bsdl_scan_files (urj_chain_t *chain, const char *idcode, int proc_mode)
{
char *name;
name = (char *) malloc (strlen (globs->path_list[idx])
+ strlen (elem->d_name) + 1 + 1);
/* @@@@ ToDo handle malloc error result RFHH */
name = malloc (strlen (globs->path_list[idx])
+ strlen (elem->d_name) + 1 + 1);
if (name)
{
struct stat buf;

@ -514,7 +514,8 @@ Safe_Value : IDENTIFIER
| DECIMAL_NUMBER
{
char *tmp;
tmp = (char *)malloc( 2 );
/* @@@@ ToDo check malloc result RFHH */
tmp = malloc( 2 );
snprintf( tmp, 2, "%i", $1 );
tmp[1] = '\0';
$$ = tmp;

@ -437,7 +437,7 @@ void *urj_bsdl_flex_init( int proc_mode )
return NULL;
}
if (!(extra = (urj_bsdl_scan_extra_t *)malloc( sizeof( urj_bsdl_scan_extra_t ) ))) {
if (!(extra = malloc( sizeof( urj_bsdl_scan_extra_t ) ))) {
urj_bsdl_msg( proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
yylex_destroy( scanner );
@ -518,7 +518,7 @@ static char *new_string( urj_bsdl_scan_extra_t *extra, const char *str )
size_t n_str_size;
n_str_size = strlen( str ) + 1;
if ((n_str = (char *)malloc( n_str_size )))
if ((n_str = malloc( n_str_size )))
{
strncpy( n_str, str, n_str_size-1 );
n_str[n_str_size-1] = '\0'; /* set very last element to EOS */

@ -150,7 +150,7 @@ urj_bsdl_emit_ports (urj_bsdl_jtag_ctrl_t *jc)
*/
name_len = strlen (name->string);
str_len = name_len + 1 + 10 + 1 + 1;
if ((port_string = (char *) malloc (str_len)) != NULL)
if ((port_string = malloc (str_len)) != NULL)
{
cmd[1] = port_string;
@ -577,7 +577,7 @@ parse_vhdl_elem (urj_bsdl_parser_priv_t *priv, urj_bsdl_vhdl_elem_t *elem)
/* allocate enough memory for total buffer */
buf_len = name_string_len + 1 + elem_string_len + 1;
buf = (char *) malloc (buf_len);
buf = malloc (buf_len);
if (!buf)
{
urj_bsdl_msg (priv->jtag_ctrl->proc_mode,

@ -612,7 +612,8 @@ static void Init_Text( urj_bsdl_vhdl_parser_priv_t *priv )
{
if (priv->len_buffer == 0)
{
priv->buffer = (char *)malloc( 160 );
/* @@@@ ToDo check malloc result RFHH */
priv->buffer = malloc( 160 );
priv->len_buffer = 160;
}
priv->buffer[0] = '\0';
@ -646,7 +647,8 @@ static void Store_Text( urj_bsdl_vhdl_parser_priv_t *priv, char *Source )
req_len = strlen( priv->buffer ) + strlen( Source ) + 1;
if (req_len > priv->len_buffer)
{
priv->buffer = (char *)realloc( priv->buffer, req_len );
/* @@@@ ToDo check realloc result RFHH */
priv->buffer = realloc( priv->buffer, req_len );
priv->len_buffer = req_len;
}
strcat( priv->buffer, Source );
@ -825,7 +827,7 @@ urj_bsdl_vhdl_parser_priv_t *urj_vhdl_parser_init( FILE *f, urj_bsdl_jtag_ctrl_t
{
urj_bsdl_vhdl_parser_priv_t *new_priv;
if (!(new_priv = (urj_bsdl_vhdl_parser_priv_t *)malloc( sizeof( urj_bsdl_vhdl_parser_priv_t ) )))
if (!(new_priv = malloc( sizeof( urj_bsdl_vhdl_parser_priv_t ) )))
{
urj_bsdl_msg( jtag_ctrl->proc_mode,
BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
@ -919,7 +921,7 @@ static void urj_vhdl_port_add_name( urj_bsdl_vhdl_parser_priv_t *priv, char *nam
urj_bsdl_port_desc_t *pd = &(priv->tmp_port_desc);
urj_bsdl_string_elem_t *new_string;
new_string = (urj_bsdl_string_elem_t *)malloc( sizeof( urj_bsdl_string_elem_t ) );
new_string = malloc( sizeof( urj_bsdl_string_elem_t ) );
if (new_string)
{
new_string->next = pd->names_list;
@ -997,7 +999,7 @@ static void urj_vhdl_port_add_range( urj_bsdl_vhdl_parser_priv_t *priv, int low,
static void urj_vhdl_port_apply_port( urj_bsdl_vhdl_parser_priv_t *priv )
{
urj_bsdl_port_desc_t *tmp_pd = &(priv->tmp_port_desc);
urj_bsdl_port_desc_t *pd = (urj_bsdl_port_desc_t *)malloc( sizeof( urj_bsdl_port_desc_t ) );
urj_bsdl_port_desc_t *pd = malloc( sizeof( urj_bsdl_port_desc_t ) );
if (pd)
{
@ -1038,7 +1040,7 @@ static void add_elem( urj_bsdl_vhdl_parser_priv_t *priv, urj_bsdl_vhdl_elem_t *e
#if 0
static void set_attr_bool( urj_bsdl_vhdl_parser_priv_t *priv, char *name, int value )
{
urj_bsdl_vhdl_elem_t *el = (urj_bsdl_vhdl_elem_t *)malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
urj_bsdl_vhdl_elem_t *el = malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
if (el)
{
@ -1055,8 +1057,8 @@ static void set_attr_bool( urj_bsdl_vhdl_parser_priv_t *priv, char *name, int va
static void set_attr_decimal( urj_bsdl_vhdl_parser_priv_t *priv, char *name, int value )
{
urj_bsdl_vhdl_elem_t *el = (urj_bsdl_vhdl_elem_t *)malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
char *string = (char *)malloc( 10 );
urj_bsdl_vhdl_elem_t *el = malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
char *string = malloc( 10 );
if (el && string)
{
@ -1074,7 +1076,7 @@ static void set_attr_decimal( urj_bsdl_vhdl_parser_priv_t *priv, char *name, int
static void set_attr_string( urj_bsdl_vhdl_parser_priv_t *priv, char *name, char *string )
{
urj_bsdl_vhdl_elem_t *el = (urj_bsdl_vhdl_elem_t *)malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
urj_bsdl_vhdl_elem_t *el = malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
/* skip certain attributes */
if ( (strcasecmp( name, "DESIGN_WARNING" ) == 0)
@ -1105,7 +1107,7 @@ static void set_attr_string( urj_bsdl_vhdl_parser_priv_t *priv, char *name, char
#if 0
static void set_attr_real( urj_bsdl_vhdl_parser_priv_t *priv, char *name, char *string )
{
urj_bsdl_vhdl_elem_t *el = (urj_bsdl_vhdl_elem_t *)malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
urj_bsdl_vhdl_elem_t *el = malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
if (el)
{
@ -1123,7 +1125,7 @@ static void set_attr_real( urj_bsdl_vhdl_parser_priv_t *priv, char *name, char *
#if 0
static void set_attr_const( urj_bsdl_vhdl_parser_priv_t *priv, char *name, char *string )
{
urj_bsdl_vhdl_elem_t *el = (urj_bsdl_vhdl_elem_t *)malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
urj_bsdl_vhdl_elem_t *el = malloc( sizeof( urj_bsdl_vhdl_elem_t ) );
if (el)
{

@ -366,7 +366,7 @@ void *urj_vhdl_flex_init( FILE *f, int proc_mode )
}
yyset_in( f, scanner );
if (!(extra = (urj_bsdl_scan_extra_t *)malloc( sizeof( urj_bsdl_scan_extra_t ) )))
if (!(extra = malloc( sizeof( urj_bsdl_scan_extra_t ) )))
{
urj_bsdl_msg( proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
@ -449,7 +449,7 @@ static char *new_string( urj_bsdl_scan_extra_t *extra, const char *str )
size_t n_str_size;
n_str_size = strlen( str ) + 1;
if ((n_str = (char *)malloc( n_str_size )))
if ((n_str = malloc( n_str_size )))
{
strncpy( n_str, str, n_str_size-1 );
n_str[n_str_size-1] = '\0'; /* set very last element to EOS */
@ -498,12 +498,12 @@ void urj_vhdl_flex_switch_file( yyscan_t scanner, char *filename )
const char *db_path = urj_cmd_jtag_get_data_dir();
char *db_file;
if ((db_file = (char *)malloc( strlen( db_path ) +
1 + /* "/" */
4 + /* "bsdl" */
1 + /* "/" */
strlen( filename ) +
1 )))
if ((db_file = malloc( strlen( db_path ) +
1 + /* "/" */
4 + /* "bsdl" */
1 + /* "/" */
strlen( filename ) +
1 )))
{
strcpy( db_file, db_path );
strcat( db_file, "/" );

@ -305,9 +305,7 @@ fjmem_query_blocks (urj_chain_t *chain, urj_part_t *part, urj_bus_t *bus)
block_param_t *bl;
int nbytes;
if ((bl =
(block_param_t *) calloc (1,
sizeof (block_param_t))) == NULL)
if ((bl = calloc (1, sizeof (block_param_t))) == NULL)
{
printf (_("out of memory\n"));
failed |= 1;

@ -87,7 +87,7 @@ mpc5200_bus_new (urj_chain_t *chain, const urj_bus_driver_t *driver,
return NULL;
bus->driver = driver;
bus->params = bp = (bus_params_t *) calloc (1, sizeof (bus_params_t));
bus->params = bp = calloc (1, sizeof (bus_params_t));
if (!bus->params)
{
free (bus);

@ -100,7 +100,7 @@ cmd_cable_run (urj_chain_t *chain, char *params[])
cable = calloc (1, sizeof (urj_cable_t));
if (!cable)
{
printf (_("%s(%d) malloc failed!\n"), __FILE__, __LINE__);
printf (_("%s(%d) calloc failed!\n"), __FILE__, __LINE__);
return 1;
}

@ -44,6 +44,7 @@ cmd_part_run (urj_chain_t *chain, char *params[])
{
urj_part_t *part;
part = chain->parts->parts[chain->active_part];
/* @@@@ ToDo RFHH check malloc result */
part->alias = malloc (strlen (params[2]) + 1);
strcpy (part->alias, params[2]);
return 1;

@ -267,15 +267,9 @@ urj_flash_cfi_detect (urj_bus_t *bus, uint32_t adr,
num_of_banks = read1 (BANK_ORGANIZATION_OFFSET);
else
num_of_banks = 0;
pri_vendor_tbl =
(urj_flash_cfi_amd_pri_extened_query_structure_t *) calloc (1,
sizeof
(urj_flash_cfi_amd_pri_extened_query_structure_t)
+
num_of_banks
*
sizeof
(uint8_t));
pri_vendor_tbl = calloc (1,
sizeof (urj_flash_cfi_amd_pri_extened_query_structure_t)
+ num_of_banks * sizeof (uint8_t));
if (!pri_vendor_tbl)
{
write1 (0, CFI_CMD_READ_ARRAY1);

@ -233,8 +233,7 @@ urj_jim_alloc_device (int num_sregs, const int reg_size[])
{
int i, r;
urj_jim_device_t *dev =
(urj_jim_device_t *) malloc (sizeof (urj_jim_device_t));
urj_jim_device_t *dev = malloc (sizeof (urj_jim_device_t));
if (dev == NULL)
{
@ -242,10 +241,7 @@ urj_jim_alloc_device (int num_sregs, const int reg_size[])
return NULL;
}
dev->sreg =
(urj_jim_shift_reg_t *) malloc (num_sregs *
sizeof (urj_jim_shift_reg_t));
dev->sreg = malloc (num_sregs * sizeof (urj_jim_shift_reg_t));
if (dev->sreg == NULL)
{
free (dev);
@ -256,9 +252,8 @@ urj_jim_alloc_device (int num_sregs, const int reg_size[])
for (r = 0, i = 0; i < num_sregs; i++)
{
dev->sreg[i].len = reg_size[i];
dev->sreg[i].reg =
(uint32_t *) calloc (((reg_size[i] + 31) / 32),
sizeof (uint32_t));
dev->sreg[i].reg = calloc (((reg_size[i] + 31) / 32),
sizeof (uint32_t));
if (dev->sreg[i].reg == NULL)
r++;
}
@ -290,7 +285,7 @@ urj_jim_init (void)
{
urj_jim_state_t *s;
s = (urj_jim_state_t *) malloc (sizeof (urj_jim_state_t));
s = malloc (sizeof (urj_jim_state_t));
if (s == NULL)
{
printf ("Out of memory!\n");

@ -357,7 +357,7 @@ urj_svf_build_bit_string (char *hex_string, int len)
char *hex_string_pos;
int hex_string_idx;
if (!(bit_string = (char *) calloc (len + 1, sizeof (char))))
if (!(bit_string = calloc (len + 1, sizeof (char))))
{
printf (_("out of memory"));
return (NULL);
@ -548,7 +548,7 @@ urj_svf_all_care (char **string, double number)
num = num % 4 == 0 ? num / 4 : num / 4 + 1;
/* build string with all cares */
if (!(ptr = (char *) calloc (num + 1, sizeof (char))))
if (!(ptr = calloc (num + 1, sizeof (char))))
{
printf (_("out of memory"));
return (0);
@ -1195,8 +1195,7 @@ urj_svf_run (urj_chain_t *chain, FILE * SVF_FILE, int stop_on_mismatch,
len = priv.part->instruction_length;
if (len > 0)
{
if ((instruction_string =
(char *) calloc (len + 1, sizeof (char))) != NULL)
if ((instruction_string = calloc (len + 1, sizeof (char))) != NULL)
{
memset (instruction_string, '1', len);
instruction_string[len] = '\0';

@ -366,7 +366,7 @@ void *urj_svf_flex_init(FILE *f, int num_lines, int print_progress)
yyset_in(f, scanner);
if (!(extra = (urj_svf_scanner_extra_t *)malloc(sizeof(urj_svf_scanner_extra_t)))) {
if (!(extra = malloc(sizeof(urj_svf_scanner_extra_t)))) {
printf( _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
yylex_destroy(scanner);
return NULL;

@ -54,7 +54,7 @@ extend_cmd_buffer (urj_tap_cable_cmd_xfer_cx_cmd_t *cmd)
{
cmd->buf_len *= 2;
if (cmd->buf)
cmd->buf = (uint8_t *) realloc (cmd->buf, cmd->buf_len);
cmd->buf = realloc (cmd->buf, cmd->buf_len);
}
return cmd->buf ? 1 : 0;
@ -196,13 +196,12 @@ urj_tap_cable_cx_cmd_queue (urj_tap_cable_cmd_xfer_cx_cmd_root_t *cmd_root,
uint32_t to_recv)
{
urj_tap_cable_cmd_xfer_cx_cmd_t *cmd =
(urj_tap_cable_cmd_xfer_cx_cmd_t *)
malloc (sizeof (urj_tap_cable_cmd_xfer_cx_cmd_t));
if (cmd)
{
cmd->buf_len = 64;
if ((cmd->buf = (uint8_t *) malloc (cmd->buf_len)) == NULL)
if ((cmd->buf = malloc (cmd->buf_len)) == NULL)
{
free (cmd);
cmd = NULL;

@ -1732,7 +1732,7 @@ ft2232_connect (char *params[], urj_cable_t *cable)
if ((result = urj_tap_cable_generic_usbconn_connect (params, cable)) != 0)
return result;
cable_params = (params_t *) malloc (sizeof (params_t));
cable_params = malloc (sizeof (params_t));
if (!cable_params)
{
printf (_("%s(%d) malloc failed!\n"), __FILE__, __LINE__);

@ -289,6 +289,7 @@ urj_tap_cable_generic_flush_using_transfer (urj_cable_t *cable,
if (in == NULL || out == NULL)
{
/* @@@@ RFHH free(NULL) is correct */
if (in != NULL)
free (in);
if (out != NULL)

@ -74,7 +74,7 @@ usbblaster_connect (char *params[], urj_cable_t *cable)
if ((result = urj_tap_cable_generic_usbconn_connect (params, cable)) != 0)
return result;
cable_params = (params_t *) malloc (sizeof (params_t));
cable_params = malloc (sizeof (params_t));
if (!cable_params)
{
printf (_("%s(%d) malloc failed!\n"), __FILE__, __LINE__);

@ -477,7 +477,7 @@ urj_tap_manual_add (urj_chain_t *chain, int instr_len)
cmd[1] = "BYPASS";
cmd[3] = "BR";
cmd[4] = NULL;
str = (char *) calloc (instr_len + 1, sizeof (char));
str = calloc (instr_len + 1, sizeof (char));
if (str == NULL)
{
printf (_("Out of memory!\n"));

@ -120,8 +120,7 @@ usbconn_ftd2xx_flush (ftd2xx_param_t *p)
/* extend receive buffer */
p->recv_buf_len = p->recv_write_idx + p->to_recv;
if (p->recv_buf)
p->recv_buf =
(uint8_t *) realloc (p->recv_buf, p->recv_buf_len);
p->recv_buf = realloc (p->recv_buf, p->recv_buf_len);
}
if (!p->recv_buf)
@ -242,7 +241,7 @@ usbconn_ftd2xx_write (urj_usbconn_t *conn, uint8_t *buf, int len, int recv)
{
p->send_buf_len = p->send_buffered + len;
if (p->send_buf)
p->send_buf = (uint8_t *) realloc (p->send_buf, p->send_buf_len);
p->send_buf = realloc (p->send_buf, p->send_buf_len);
}
if (p->send_buf)
@ -283,12 +282,12 @@ usbconn_ftd2xx_connect (const char **param, int paramc,
{
p->send_buf_len = URJ_USBCONN_FTDX_MAXSEND;
p->send_buffered = 0;
p->send_buf = (uint8_t *) malloc (p->send_buf_len);
p->send_buf = malloc (p->send_buf_len);
p->recv_buf_len = URJ_USBCONN_FTD2XX_MAXRECV;
p->to_recv = 0;
p->recv_write_idx = 0;
p->recv_read_idx = 0;
p->recv_buf = (uint8_t *) malloc (p->recv_buf_len);
p->recv_buf = malloc (p->recv_buf_len);
}
if (!p || !c || !p->send_buf || !p->recv_buf)

@ -103,8 +103,7 @@ usbconn_ftdi_flush (ftdi_param_t *p)
/* extend receive buffer */
p->recv_buf_len = p->recv_write_idx + p->to_recv;
if (p->recv_buf)
p->recv_buf =
(uint8_t *) realloc (p->recv_buf, p->recv_buf_len);
p->recv_buf = realloc (p->recv_buf, p->recv_buf_len);
}
if (!p->recv_buf)
@ -208,7 +207,7 @@ usbconn_ftdi_write (urj_usbconn_t *conn, uint8_t *buf, int len, int recv)
{
p->send_buf_len = p->send_buffered + len;
if (p->send_buf)
p->send_buf = (uint8_t *) realloc (p->send_buf, p->send_buf_len);
p->send_buf = realloc (p->send_buf, p->send_buf_len);
}
if (p->send_buf)
@ -247,12 +246,12 @@ usbconn_ftdi_connect (const char **param, int paramc,
{
p->send_buf_len = URJ_USBCONN_FTDX_MAXSEND;
p->send_buffered = 0;
p->send_buf = (uint8_t *) malloc (p->send_buf_len);
p->send_buf = malloc (p->send_buf_len);
p->recv_buf_len = URJ_USBCONN_FTDI_MAXRECV;
p->to_recv = 0;
p->recv_write_idx = 0;
p->recv_read_idx = 0;
p->recv_buf = (uint8_t *) malloc (p->recv_buf_len);
p->recv_buf = malloc (p->recv_buf_len);
}
if (!p || !c || !fc || !p->send_buf || !p->recv_buf)

Loading…
Cancel
Save