Skip to content

Commit 7ccc1c3

Browse files
authored
Strip null characters from variable name in getvarnames (JuliaIO#210)
This updates `getvarnames` to match the functionality of `read_matrix` using `strip` to deal with the possibility of terminal (or beginning) null characters. Note: `getvarnames` is only used when 1) checking if a `Matlabv4File` has a specific key, 2) getting the keys of such a file OR 3) `read`ing a specific variable from such a file.
1 parent 50a9156 commit 7ccc1c3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/MAT_v4.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function getvarnames(matfile::Matlabv4File)
187187
M, O, P, T, mrows, ncols, imagf, namlen = read_header(matfile.ios, matfile.swap_bytes)
188188
f = matfile.ios
189189

190-
name = String(read_bswap(f, M==mBIG_ENDIAN, Vector{UInt8}(undef, namlen))[1:end-1])
190+
name = strip(String(read_bswap(f, M==mBIG_ENDIAN, Vector{UInt8}(undef, namlen))), '\0')
191191
varnames[name] = offset
192192
imag_offset = 0
193193
skip(f, mrows*ncols*sizeof(pTYPE[P]))

0 commit comments

Comments
 (0)