Skip to content

Commit

Permalink
Fixed string concat to cstring conversion (#427)
Browse files Browse the repository at this point in the history
* Fixed string concat to cstring conversion

* Minor stylistic adjustment
  • Loading branch information
wnats authored Dec 8, 2023
1 parent 35b5c14 commit 63c971d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions test-cases/execution/string_concat_to_cstring.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
012
Empty file.
3 changes: 3 additions & 0 deletions test-cases/execution/string_concat_to_cstring.wybe
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
?str = ("0" ,, "1") ,, "2"

!println(c_string(str))
3 changes: 1 addition & 2 deletions wybelibs/wybe/string.wybe
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub def c_string(s:_):c_string = str where {
| else ::
?len = length(s) + 1
foreign lpvm alloc(len, ?str)
foreign lpvm mutate(str, ?str, len, true, len, 0, '\0')
foreign lpvm mutate(str, ?str, len - 1, true, len, 0, '\0')
?offset = 0
pack(s, !str, len, !offset)
}
Expand Down Expand Up @@ -180,7 +180,6 @@ def pack(s:_, !raw:c_string, size:int, !offset:int) {
| concat(?left, ?right) ::
pack(left, !raw, size, !offset)
pack(right, !raw, size, !offset)
incr(!offset)
| slice(_, _) ::
for ?c in s {
foreign lpvm mutate(raw, ?raw, offset, true, size, 0, c)
Expand Down

0 comments on commit 63c971d

Please sign in to comment.