Word8VectorSlice: mapping a subslice produces wrong result or crashes SML/NJ #239
Closed
1 of 5 tasks
Labels
basis-lib
problem with Standard ML Basis library
bug
Something isn't working
fixed-in-2022.1
issue is fixed in the 2022.1 release
gforge
bug (or feature request) ported from smlnj-gforge repository
Version
110.99.2
Operating System
OS Version
No response
Processor
Any
Component
Basis Library
Severity
Major
Description of the problem
There are some inputs for which using
Word8VectorSlice.map
on the result ofWord8VectorSlice.subslice
would either produce an incorrect result, or wouldcause SML/NJ to crash with "Fatal error -- bad object tag 28".
I have attached source code that creates a Word8VectorSlice, then creates a
subslice of it using Word8VectorSlice.subslice, then maps the subslice using
Word8VectorSlice.map, followed by printing the results of the map operation.
Run the code using
sml < the-program.sml
. The "Fatal error" only occursoccasionally. You may observe the fatal error by running the program repeatedly
using this shell snippet:
Transcript
Expected Behavior
No response
Steps to Reproduce
(* This is supposed to behave like an identity function for Word8VectorSlice.
fun uselessMap slice =
Word8VectorSlice.full (Word8VectorSlice.map (fn word => word) slice)
fun printWord8VectorSlice slice =
Word8VectorSlice.appi
(fn (index, word) => (
print ("CHAR " ^ Int.toString index ^ ": ");
print (Char.toString (Char.chr (Word8.toInt word)));
print "\n"))
slice
fun charsToWord8List charList =
List.map (fn c => Word8.fromInt (Char.ord c)) charList
fun main () =
let
val vec = Word8Vector.fromList (
charsToWord8List [#"m", #"y", #" ", #"f", #"a", #"t", #"h", #"e", #"r"])
val slice = Word8VectorSlice.full vec (* Word8Vector.vector -> Word8VectorSlice.slice )
val father = Word8VectorSlice.subslice (slice, 3, NONE) ( Exclude "my " )
val mappedFather = uselessMap father
in
print ("father length: " ^ Int.toString (Word8VectorSlice.length father) ^ "\n");
printWord8VectorSlice father;
( Mapped father *)
print ("mappedFather length: " ^ Int.toString (Word8VectorSlice.length mappedFather) ^ "\n");
printWord8VectorSlice mappedFather;
()
end
val () = main ()
Additional Information
No response
Email address
No response
Comments from smlnj-gforge
Original smlnj-gforge bug number 306
Submitted on 2022-59-10 at 10:5900
comment by @JohnReppy on 2022-39-10 15:3900 +000 UTC
Stupid indexing bug in Word8Slice.map code. Does not appear to affect any of the other vector-slice modules. Fixed for 110.99.3 and 2022.1.
The text was updated successfully, but these errors were encountered: