Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#108] off-by-one error in Util/dynamic-array.sml; iterators crash

Date:
2012-10-21 18:59
Priority:
3
State:
Closed
Submitted by:
Bug Submitter (webuser)
Assigned to:
John Reppy (jhr)
Machine Architecture:
All
Operating System:
Generic Unix
Component:
SML/NJ Library
Resolution:
Fixed
Severity:
Major
OS Version:
SML/NJ Version:
110.74
Keywords:
URL:
Transcript (of reproduction):
Standard ML of New Jersey v110.74 [built: Sun Oct 21 20:44:49 2012] - val a = DynamicArray.array (4, NONE : int option); DynamicArray.find (fn x = false) a; (* Other iterators, such as foldli, also raise Subscript. *) [autoloading] [library $SMLNJ-LIB/Util/smlnj-lib.cm is stable] [autoloading done] val a = - : int option DynamicArray.array - uncaught exception Subscript [subscript out of bounds] raised at: Basis/Implementation/array-slice.sml:54.55-54.64 -
Source (for reproduction):
val a = DynamicArray.array (4, NONE : int option); DynamicArray.find (fn x = false) a; (* Other iterators, such as foldli, also raise Subscript. *)
Summary:
off-by-one error in Util/dynamic-array.sml; iterators crash

Detailed description
The iterators in DynamicArray (Util/dynamic-array.sml) raise Subscript in most circumstances,
because the `slice\ function uses !bnd, which is the *last* used element, instead of
!bnd + 1, which is the upper bound needed by ArraySlice.
Fix:
--- dynamic-array.sml 2009-05-13 15:17:00.000000000 +0200
+++ /Users/joshua/nj-util/dynamic-array.sml 2012-10-21 20:48:45.000000000 +0200
@@ -95,7 +95,7 @@

(* get the array slice that covers the defined portion of the array *)
fun slice (BLOCK(arr, _, bnd)) =
- ArraySlice.slice(!arr, 0, SOME(!bnd))
+ ArraySlice.slice(!arr, 0, SOME(!bnd + 1))

(* we implement the iterators by using the array slice operations *)
fun vector arr = ArraySlice.vector (slice arr)


Submitted via web form by Joshua Dunfield joshua@mpi-sws.org

Comments:

Message  ↓
Date: 2012-10-30 10:09
Sender: John Reppy

Fixed for 110.76.

Attached Files:

Changes

Field Old Value Date By
status_idOpen2012-10-30 10:09jhr
assigned_tonone2012-10-30 10:09jhr
close_date2012-10-30 10:092012-10-30 10:09jhr
Machine ArchitectureNone2012-10-30 10:09jhr
ResolutionNone2012-10-30 10:09jhr