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 of
Word8VectorSlice.subslice would either produce an incorrect result, or would
cause 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 occurs
occasionally. You may observe the fatal error by running the program repeatedly
using this shell snippet:
while :; do sml < the-program.sml; [ $? -ne 0 ] && break; done
Transcript
This is the result that SML/NJ may produce:
father length: 6
CHAR 0: f
CHAR 1: a
CHAR 2: t
CHAR 3: h
CHAR 4: e
CHAR 5: r
mappedFather length: 6
CHAR 0: \^@
CHAR 1: \^@
CHAR 2: \^@
CHAR 3: f
CHAR 4: a
CHAR 5: t
This is supposed to be the correct result:
father length: 6
CHAR 0: f
CHAR 1: a
CHAR 2: t
CHAR 3: h
CHAR 4: e
CHAR 5: r
mappedFather length: 6
CHAR 0: f
CHAR 1: a
CHAR 2: t
CHAR 3: h
CHAR 4: e
CHAR 5: r
Expected Behavior
No response
Steps to Reproduce
(* This is supposed to behave like an identity function for Word8VectorSlice.
* Word8VectorSlice.slice -> Word8VectorSlice.slice *)
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-05-10 at 10:59:00
comment by @JohnReppy on 2022-05-10 15:39:00 +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.
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.mapon the result ofWord8VectorSlice.subslicewould 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
Additional Information
No response
Email address
No response
Comments from smlnj-gforge
Original smlnj-gforge bug number 306
Submitted on 2022-05-10 at 10:59:00
comment by @JohnReppy on 2022-05-10 15:39:00 +000 UTC
Stupid indexing bug in
Word8Slice.mapcode. Does not appear to affect any of the other vector-slice modules. Fixed for 110.99.3 and 2022.1.