FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
array_boundchk.c
Go to the documentation of this file.
1
/* Array bound checking functions */
2
3
#include "
fb.h
"
4
5
static
void
*
hThrowError
(
int
linenum,
const
char
*fname )
6
{
7
/* call user handler if any defined */
8
return
(
void
*)
fb_ErrorThrowEx
(
FB_RTERROR_OUTOFBOUNDS
, linenum, fname,
NULL
,
NULL
);
9
}
10
11
FBCALL
void
*
fb_ArrayBoundChk
12
(
13
ssize_t
idx
,
14
ssize_t lbound,
15
ssize_t ubound,
16
int
linenum,
17
const
char
*fname
18
)
19
{
20
if
( (idx < lbound) || (idx > ubound) )
21
return
hThrowError
( linenum, fname );
22
else
23
return
NULL
;
24
}
25
26
FBCALL
void
*
fb_ArraySngBoundChk
27
(
28
size_t
idx,
29
size_t
ubound,
30
int
linenum,
31
const
char
*fname
32
)
33
{
34
/* Assuming lbound is 0, we know ubound must be >= 0, and we can treat
35
index as unsigned too, possibly letting it overflow to a very big
36
value (if it was negative), reducing the bound check to a single
37
unsigned comparison. */
38
if
( idx > ubound )
39
return
hThrowError
( linenum, fname );
40
else
41
return
NULL
;
42
}
rtlib
array_boundchk.c
Generated on Thu Jan 23 2014 19:40:07 for FreeBASIC by
1.8.4