Skip to content

Commit 7a3c235

Browse files
committed
add gitlab ci
1 parent 98e91a9 commit 7a3c235

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/MAT_v4.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function read_matrix(f::IO, swap_bytes::Bool)
131131
# surprises, we produce an empty array in both cases.
132132
return ("", Matrix{Union{}}(undef, 0, 0))
133133
end
134-
name = String(read_bswap(f, M==mBIG_ENDIAN, Vector{UInt8}(undef, namlen))[1:end-1])
134+
name = strip(String(read_bswap(f, M==mBIG_ENDIAN, Vector{UInt8}(undef, namlen))), '\0')
135135
if T == tNUMERIC || T == tSPARSE
136136
real_data = read_bswap(f, M==mBIG_ENDIAN, Vector{pTYPE[P]}(undef, ncols*mrows))
137137
if T == tNUMERIC && imagf == imagfCOMPLEX

test/readwrite4.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,26 @@ for filename in readdir("v4")
5050
check("v4/tmp.mat", d)
5151
rm("v4/tmp.mat")
5252
end
53+
54+
# support read var name without '\0', xref https://github.com/JuliaIO/MAT.jl/pull/202
55+
let tmp = "v4/tmp.mat"
56+
data = rand(1,9);
57+
open(tmp, "w") do fid
58+
M, N = size(data);
59+
data_type = 0;
60+
name = "testnamelen";
61+
L = ncodeunits(name)
62+
write(fid, Int32(data_type));
63+
write(fid, Int32(M));
64+
write(fid, Int32(N));
65+
write(fid, Int32(0));
66+
write(fid, Int32(L));
67+
# name is store without null-terminator '\0'
68+
write(fid, name)
69+
write(fid, data)
70+
end
71+
d = MAT.matread(tmp)
72+
@test haskey(d, "testnamelen")
73+
@test first(values(d)) == data
74+
rm(tmp)
75+
end

0 commit comments

Comments
 (0)