Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bounds checking
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Index checking== Index checking means that, in all [[Expression (programming)|expressions]] indexing an array, the index value is checked against the bounds of the array (which were established when the array was defined), and if the index is out-of-bounds, further execution is suspended via some sort of error. Because reading or especially writing a value outside the bounds of an array may cause the program to malfunction or crash or enable security vulnerabilities (see [[buffer overflow]]), index checking is a part of many [[High-level programming language|high-level languages]]. Early compiled [[programming language]]s with index checking ability included [[ALGOL 60]], [[ALGOL 68]] and [[Pascal (programming language)|Pascal]], as well as interpreted programming languages such as [[BASIC]]. Many programming languages, such as [[C (programming language)|C]], never perform automatic bounds checking to raise speed. However, this leaves many [[off-by-one error]]s and [[buffer overflow]]s uncaught. Many programmers believe these languages sacrifice too much for rapid execution.<ref>{{Cite book |doi=10.1109/DISCEX.2000.821514|chapter=Buffer overflows: Attacks and defenses for the vulnerability of the decade|title=Proceedings DARPA Information Survivability Conference and Exposition. DISCEX'00|volume=2|pages=119β129|year=1999|last1=Cowan|first1=C|last2=Wagle|first2=F|last3=Calton Pu|last4=Beattie|first4=S|last5=Walpole|first5=J|isbn=978-0-7695-0490-2|s2cid=167759976}}</ref> In his 1980 [[Turing Award]] lecture, [[C. A. R. Hoare]] described his experience in the design of [[ALGOL 60]], a language that included bounds checking, saying: <blockquote>A consequence of this principle is that every occurrence of every subscript of every subscripted variable was on every occasion checked at run time against both the upper and the lower declared bounds of the array. Many years later we asked our customers whether they wished us to provide an option to switch off these checks in the interest of efficiency on production runs. Unanimously, they urged us not toβthey already knew how frequently subscript errors occur on production runs where failure to detect them could be disastrous. I note with fear and horror that even in 1980, language designers and users have not learned this lesson. In any respectable branch of engineering, failure to observe such elementary precautions would have long been against the law.</blockquote> Mainstream languages that enforce run time checking include [[Ada (programming language)|Ada]], [[C Sharp (programming language)|C#]], [[Haskell (programming language)|Haskell]], [[Java (programming language)|Java]], [[JavaScript]], [[Lisp (programming language)|Lisp]], [[PHP]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Rust (programming language)|Rust]], and [[Visual Basic]]. The [[D (programming language)|D]] and [[OCaml]] languages have run time bounds checking that is enabled or disabled with a compiler switch. In [[C++]] run time checking is not part of the language, but part of the [[Standard Template Library|STL]] and is enabled with a compiler switch (_GLIBCXX_DEBUG=1 or _LIBCPP_DEBUG=1). C# also supports ''unsafe regions'': sections of code that (among other things) temporarily suspend bounds checking to raise efficiency. These are useful for speeding up small time-critical bottlenecks without sacrificing the safety of a whole program. The [[JS++]] programming language is able to analyze if an array index or map key is out-of-bounds at compile time using [[existent types]], which is a [[Nominal type system|nominal type]] describing whether the index or key is within-bounds or out-of-bounds and guides code generation. Existent types have been shown to add only {{Clarify span|1ms overhead|date=February 2025}} to compile times.<ref>{{Cite web | url=https://www.onux.com/jspp/blog/jspp-0-9-0-efficient-compile-time-analysis-of-out-of-bounds-errors/ | archive-url=https://web.archive.org/web/20190112060200/https://www.onux.com/jspp/blog/jspp-0-9-0-efficient-compile-time-analysis-of-out-of-bounds-errors/| archive-date=2019-01-12| title=JS++ 0.9.0: Efficient Compile Time Analysis of Out-of-Bounds Errors β JS++ Blog| date=11 January 2019}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)