Skip to content

Commit 7195b18

Browse files
committed
Fix off-by-one error in unsafe_string(::fixed_string)
1 parent 817308a commit 7195b18

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/string_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function unsafe_string(x::fixed_string{T}) where {T <: Integer}
2323
data_array = reinterpret(UInt8, [x.data])
2424
zero_idx = findfirst(data_array, 0)
2525
if zero_idx == 0
26-
zero_idx = sizeof(T)
26+
zero_idx = sizeof(T) + 1
2727
end
2828

29-
str = String(data_array[1:zero_idx])
29+
str = String(data_array[1:zero_idx-1])
3030
if !isvalid(str)
3131
return "$(zero_idx)-byte String of invalid UTF-8 data"
3232
end

0 commit comments

Comments
 (0)