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

Add iniGetIntInRange() for range-enforced integer values

If you're going to use a read key value as say, an index into fixed-length array, then you better be sure it's within an expected range.
parent f4d66c23
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -1691,6 +1691,23 @@ int iniGetInteger(str_list_t list, const char* section, const char* key, int def ...@@ -1691,6 +1691,23 @@ int iniGetInteger(str_list_t list, const char* section, const char* key, int def
return(parseInteger(vp)); return(parseInteger(vp));
} }
int iniGetIntInRange(str_list_t list, const char* section, const char* key, int min, int deflt, int max)
{
char* vp=NULL;
int result;
get_value(list, section, key, NULL, &vp, /* literals_supported: */FALSE);
if(vp==NULL || *vp==0) /* blank value or missing key */
return deflt;
result = parseInteger(vp);
if(result < min || result > max)
return deflt;
return result;
}
uint iniGetUInteger(str_list_t list, const char* section, const char* key, uint deflt) uint iniGetUInteger(str_list_t list, const char* section, const char* key, uint deflt)
{ {
char* vp=NULL; char* vp=NULL;
......
...@@ -13,21 +13,9 @@ ...@@ -13,21 +13,9 @@
* See the GNU Lesser General Public License for more details: lgpl.txt or * * See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html * * http://www.fsf.org/copyleft/lesser.html *
* * * *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see * * For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html * * http://www.synchro.net/source.html *
* * * *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. * * Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/ ****************************************************************************/
...@@ -164,6 +152,8 @@ DLLEXPORT str_list_t iniGetStringList(str_list_t, const char* section, const ch ...@@ -164,6 +152,8 @@ DLLEXPORT str_list_t iniGetStringList(str_list_t, const char* section, const ch
,const char* sep, const char* deflt); ,const char* sep, const char* deflt);
DLLEXPORT int iniGetInteger(str_list_t, const char* section, const char* key DLLEXPORT int iniGetInteger(str_list_t, const char* section, const char* key
,int deflt); ,int deflt);
DLLEXPORT int iniGetIntInRange(str_list_t, const char* section, const char* key
,int min, int deflt, int max);
DLLEXPORT uint iniGetUInteger(str_list_t, const char* section, const char* key DLLEXPORT uint iniGetUInteger(str_list_t, const char* section, const char* key
,uint deflt); ,uint deflt);
DLLEXPORT short iniGetShortInt(str_list_t, const char* section, const char* key DLLEXPORT short iniGetShortInt(str_list_t, const char* section, const char* key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment