Skip to content
Snippets Groups Projects
Commit a466152f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Create some convenience functions for validating lib/dir/grp/sub nums

There are lot of places in the code where subnums and dirnums (especially) are compared against total_subs and/or total_dirs or >= 0 without a ton of consistency. We should migrate to use these functions for validity-checking going forward.
parent 13c520ef
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -66,6 +66,11 @@ int getlibnum(scfg_t*, const char* code);
int getsubnum(scfg_t*, const char* code);
int getgrpnum(scfg_t*, const char* code);
BOOL is_valid_dirnum(scfg_t*, int);
BOOL is_valid_libnum(scfg_t*, int);
BOOL is_valid_subnum(scfg_t*, int);
BOOL is_valid_grpnum(scfg_t*, int);
faddr_t* nearest_sysfaddr(scfg_t*, faddr_t*);
#ifdef __cplusplus
......
......@@ -822,10 +822,30 @@ int getgrpnum(scfg_t* cfg, const char* code)
int i = getdirnum(cfg, code);
if(i >= 0)
return cfg->sub[i]->grp;
return cfg->sub[i]->grp;
return i;
}
BOOL is_valid_dirnum(scfg_t* cfg, int dirnum)
{
return (dirnum >= 0) && (cfg != NULL) && (dirnum < cfg->total_dirs);
}
BOOL is_valid_libnum(scfg_t* cfg, int libnum)
{
return (libnum >= 0) && (cfg != NULL) && (libnum < cfg->total_libs);
}
BOOL is_valid_subnum(scfg_t* cfg, int subnum)
{
return (subnum >= 0) && (cfg != NULL) && (subnum < cfg->total_subs);
}
BOOL is_valid_grpnum(scfg_t* cfg, int grpnum)
{
return (grpnum >= 0) && (cfg != NULL) && (grpnum < cfg->total_grps);
}
faddr_t* nearest_sysfaddr(scfg_t* cfg, faddr_t* addr)
{
uint i;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment