Skip to content

String.allocate with NULL as the initial char value causes unexpected behaviors. #919

Open
@Liorst4

Description

@Liorst4
  • The assert that checks out of bound access in String_string_MINUS_set_BANG_ uses strlen instead of the value given to malloc. This makes the function unusable on empty strings.

  • In the core implementation the length of a string is the strlen of it, and not the initial value given to malloc, this should be documented.

(let [my-string (String.allocate 10 (Char.from-int 0))]
     (do
      (println* (String.length &my-string)) ;; Length is 0, not 10
      (String.string-set! &my-string 1 'a') ;; Assertion fails (Thinks its out of bounds because it checks that the index is less than `strlen`
      ))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions