Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word8VectorSlice: mapping a subslice produces wrong result or crashes SML/NJ #239

Closed
1 of 5 tasks
JohnReppy opened this issue Jul 16, 2022 · 0 comments
Closed
1 of 5 tasks
Assignees
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

Comments

@JohnReppy
Copy link
Contributor

Version

110.99.2

Operating System

  • All
  • Linux
  • macOS
  • Windows
  • Other Unix

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-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.

@JohnReppy JohnReppy added basis-lib problem with Standard ML Basis library bug Something isn't working gforge bug (or feature request) ported from smlnj-gforge repository labels Jul 16, 2022
@JohnReppy JohnReppy self-assigned this Jul 16, 2022
@JohnReppy JohnReppy added the fixed-in-2022.1 issue is fixed in the 2022.1 release label Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant