Commit 165a81a4 authored by Rob Swindell's avatar Rob Swindell 💬
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
......@@ -1691,6 +1691,23 @@ int iniGetInteger(str_list_t list, const char* section, const char* key, int def
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)
{
char* vp=NULL;
......
......@@ -13,21 +13,9 @@
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* 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 *
* 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. *
****************************************************************************/
......@@ -164,6 +152,8 @@ DLLEXPORT str_list_t iniGetStringList(str_list_t, const char* section, const ch
,const char* sep, const char* deflt);
DLLEXPORT int iniGetInteger(str_list_t, const char* section, const char* key
,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
,uint deflt);
DLLEXPORT short iniGetShortInt(str_list_t, const char* section, const char* key
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment