Skip to content

Commit

Permalink
check if the parameters are under zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 13, 2023
1 parent 8703b5c commit 8694157
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions lib_jtag_core/src/jtag_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ int jtagcore_loadbsdlfile(jtag_core * jc, char * path, int device)
jtag_bsdl * bsdl_file;
int i;

if ( (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE) || device == -1)
if ( (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0) || device == -1)
{
bsdl_file = load_bsdlfile(jc,path);
if (bsdl_file)
Expand Down Expand Up @@ -377,7 +377,7 @@ int jtagcore_get_dev_name(jtag_core * jc, int device, char * devname, char * bsd
{
jtag_bsdl * bsdl_file;

if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE )
if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 )
{
if (jc->devices_list[device].bsdl)
{
Expand Down Expand Up @@ -416,7 +416,7 @@ int jtagcore_get_number_of_pins(jtag_core * jc, int device)
{
jtag_bsdl * bsdl_file;

if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE )
if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 )
{
if (jc->devices_list[device].bsdl)
{
Expand All @@ -434,38 +434,43 @@ int jtagcore_get_pin_properties(jtag_core * jc, int device,int pin,char * pinnam
jtag_bsdl * bsdl_file;
int type_code;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device >= jc->nb_of_devices_in_chain ||
device >= MAX_NB_JTAG_DEVICE ||
device < 0 ||
pin < 0 )
{
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;
return JTAG_CORE_BAD_PARAMETER;
}

if (pin < bsdl_file->number_of_pins )
{
type_code = 0x00;
if (jc->devices_list[device].bsdl)
{
bsdl_file = jc->devices_list[device].bsdl;

if (pinname)
{
strncpy(pinname, bsdl_file->pins_list[pin].pinname, maxsize - 1);
pinname[maxsize - 1] = '\0';
}
if (pin < bsdl_file->number_of_pins )
{
type_code = 0x00;

if (type)
{
if (bsdl_file->pins_list[pin].ctrl_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_TRISTATES;
if (pinname)
{
strncpy(pinname, bsdl_file->pins_list[pin].pinname, maxsize - 1);
pinname[maxsize - 1] = '\0';
}

if (bsdl_file->pins_list[pin].out_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_OUTPUT;
if (type)
{
if (bsdl_file->pins_list[pin].ctrl_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_TRISTATES;

if (bsdl_file->pins_list[pin].in_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_INPUT;
if (bsdl_file->pins_list[pin].out_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_OUTPUT;

*type = type_code;
}
if (bsdl_file->pins_list[pin].in_bit_number != -1)
type_code |= JTAG_CORE_PIN_IS_INPUT;

return JTAG_CORE_NO_ERROR;
*type = type_code;
}

return JTAG_CORE_NO_ERROR;
}
}

Expand All @@ -479,7 +484,7 @@ int jtagcore_get_pin_state(jtag_core * jc, int device, int pin, int type)
int disable_state;

ret = JTAG_CORE_BAD_PARAMETER;
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && pin >= 0 )
{
if (jc->devices_list[device].bsdl)
{
Expand Down Expand Up @@ -581,7 +586,8 @@ int jtagcore_set_pin_state(jtag_core * jc, int device, int pin, int type,int sta
int disable_state;

ret = JTAG_CORE_BAD_PARAMETER;
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)

if ( device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && pin >= 0 )
{
if (jc->devices_list[device].bsdl)
{
Expand Down Expand Up @@ -644,7 +650,7 @@ int jtagcore_get_pin_id(jtag_core * jc, int device, char * pinname)
jtag_bsdl * bsdl_file;
int pin;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && pinname)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0 && pinname)
{
if (jc->devices_list[device].bsdl)
{
Expand Down Expand Up @@ -675,7 +681,7 @@ int jtagcore_set_scan_mode(jtag_core * jc, int device, int scan_mode)

ret = JTAG_CORE_BAD_PARAMETER;

if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE)
if (device < jc->nb_of_devices_in_chain && device < MAX_NB_JTAG_DEVICE && device >= 0)
{
switch (scan_mode)
{
Expand Down Expand Up @@ -1018,7 +1024,7 @@ int jtagcore_get_number_of_probes(jtag_core * jc, int probe_driver_id)
if (jc)
{
totalprobe = 0;
if( probe_driver_id < jtagcore_get_number_of_probes_drv(jc) )
if( probe_driver_id < jtagcore_get_number_of_probes_drv(jc) && probe_driver_id >= 0 )
{
if( staticdrvs[probe_driver_id].getinfosfunc(jc,staticdrvs[ probe_driver_id ].sub_drv_id, GET_DRV_DETECT, &totalprobe) == JTAG_CORE_NO_ERROR )
{
Expand All @@ -1032,7 +1038,7 @@ int jtagcore_get_number_of_probes(jtag_core * jc, int probe_driver_id)

int jtagcore_get_probe_name(jtag_core * jc, int probe_id, char * name)
{
if ( ( probe_id >> 8 ) < jtagcore_get_number_of_probes_drv(jc))
if ( ( probe_id >> 8 ) < jtagcore_get_number_of_probes_drv(jc) && probe_id >= 0 )
{
staticdrvs[ probe_id>>8 ].getinfosfunc(jc, probe_id & 0xFF, GET_DRV_DESCRIPTION, name);

Expand All @@ -1044,7 +1050,7 @@ int jtagcore_get_probe_name(jtag_core * jc, int probe_id, char * name)

int jtagcore_select_and_open_probe(jtag_core * jc, int probe_id)
{
if ( ( probe_id >> 8 ) < jtagcore_get_number_of_probes_drv(jc))
if ( ( probe_id >> 8 ) < jtagcore_get_number_of_probes_drv(jc) && probe_id >= 0 )
{
return jtagcore_loaddriver(jc, probe_id, NULL);
}
Expand Down Expand Up @@ -1091,4 +1097,3 @@ void jtagcore_deinit(jtag_core * jc)
free( jc );
}
}

0 comments on commit 8694157

Please sign in to comment.