Skip to content

Commit 274afd0

Browse files
committed
Merge pull request #13 from slimgroup/misc-bugs
Fix undef access
2 parents 9fa1dfd + 81fa020 commit 274afd0

10 files changed

+24
-16
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SegyIO"
22
uuid = "157a0f19-4d44-4de5-a0d0-07e2f0ac4dfa"
33
authors = ["Henryk Modzelewski <[email protected]>"]
4-
version = "0.8.2"
4+
version = "0.8.3"
55

66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

src/read/extract_con_headers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function extractor(con, keys, block)
3131
headers = read_con_headers(con, copy(keys), block, prealloc_traces = 10000000)
3232
ntraces = length(headers)
3333
nkeys = length(keys)
34-
header_array = Array{Int32,2}(undef, ntraces, nkeys)
34+
header_array = Array{Int32, 2}(undef, ntraces, nkeys)
3535

3636
for cur_key in 1:nkeys
3737
header_array[:,cur_key] = get_header(headers, Symbol(keys[cur_key]), scale=false)

src/read/read_block_headers.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function read_block_headers!(b::BlockScan, keys::Array{String, 1}, ns::Int, dsf:
88
s = IOBuffer(read(f, brange))
99
ntraces = Int((brange)/(240 + ns*4))
1010
fh = FileHeader()
11-
fh.bfh.ns = ns; fh.bfh.DataSampleFormat = dsf
11+
fh.bfh.ns = ns
12+
fh.bfh.DataSampleFormat = dsf
1213

1314
# Check dsf
1415
datatype = Float32
@@ -19,9 +20,10 @@ function read_block_headers!(b::BlockScan, keys::Array{String, 1}, ns::Int, dsf:
1920
end
2021

2122
th_b2s = th_byte2sample()
23+
tmph = zeros(UInt8, 240)
2224
# Read each traceheader
2325
for trace in 1:ntraces
24-
read_traceheader!(s, keys, th_b2s, headers[trace])
26+
read_traceheader!(s, keys, th_b2s, headers[trace]; th=tmph)
2527
skip(s, ns*4)
2628
end
2729

src/read/read_con.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function read_con(con::SeisCon, blocks::Array{Int,1};
2424

2525
# Pre-allocate
2626
data = Array{datatype,2}(undef, con.ns, prealloc_traces)
27-
headers = [BinaryTraceHeader() for _=1:prealloc_traces]
28-
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
27+
headers = zeros(BinaryTraceHeader, prealloc_traces)
28+
fh = FileHeader()
29+
set_fileheader!(fh.bfh, :ns, con.ns)
2930
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)
3031

3132
trace_count = 0
@@ -42,7 +43,7 @@ function read_con(con::SeisCon, blocks::Array{Int,1};
4243
println("Expanding preallocated memory")
4344
prealloc_traces *= 2
4445
data = hcat(data, Array{datatype,2}(undef, con.ns, ntraces+prealloc_traces))
45-
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
46+
append!(headers, zeros(BinaryTraceHeader, ntraces+prealloc_traces))
4647
end
4748
tmp_data = view(data, :,(trace_count+1):(trace_count+ntraces))
4849
tmp_headers = view(headers, (trace_count+1):(trace_count+ntraces))
@@ -73,7 +74,7 @@ function read_con(con::SeisCon, keys::Array{String,1}, blocks::Array{Int,1};
7374

7475
# Pre-allocate
7576
data = Array{datatype,2}(undef, con.ns, prealloc_traces)
76-
headers = [BinaryTraceHeader() for _=1:prealloc_traces]
77+
headers = zeros(BinaryTraceHeader, prealloc_traces)
7778
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
7879
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)
7980

@@ -90,7 +91,7 @@ function read_con(con::SeisCon, keys::Array{String,1}, blocks::Array{Int,1};
9091
if ~isroom
9192
println("Expanding preallocated memory")
9293
data = hcat(data, Array{datatype,2}(undef, con.ns, ntraces+prealloc_traces))
93-
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
94+
append!(headers, zeros(BinaryTraceHeader, ntraces+prealloc_traces))
9495
prealloc_traces *= 2
9596
end
9697
tmp_data = view(data, :,(trace_count+1):(trace_count+ntraces))

src/read/read_con_headers.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ function read_con_headers(con::SeisCon, keys::Array{String,1}, blocks::Array{Int
2727
in("ElevationScalar", keys) ? nothing : push!(keys, "ElevationScalar")
2828

2929
# Pre-allocate
30-
headers = Array{BinaryTraceHeader,1}(undef, prealloc_traces)
31-
fh = FileHeader(); set_fileheader!(fh.bfh, :ns, con.ns)
30+
headers = zeros(BinaryTraceHeader, prealloc_traces)
31+
fh = FileHeader()
32+
set_fileheader!(fh.bfh, :ns, con.ns)
3233
set_fileheader!(fh.bfh, :DataSampleFormat, con.dsf)
3334

3435
# Read all blocks
@@ -45,7 +46,8 @@ function read_con_headers(con::SeisCon, keys::Array{String,1}, blocks::Array{Int
4546
println("Expanding preallocated memory")
4647
prealloc_traces *= 2
4748
prealloc_traces += ntraces
48-
append!(headers, Array{BinaryTraceHeader,1}(undef, ntraces+prealloc_traces))
49+
prealloc_headers = zeros(BinaryTraceHeader, ntraces+prealloc_traces)
50+
append!(headers, prealloc_headers)
4951
end
5052
tmp_headers = view(headers, (trace_count+1):(trace_count+ntraces))
5153

src/read/read_file.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function read_file(s::IO, keys::Array{String, 1}, warn_user::Bool;
4242
ntraces = Int((end_byte - start_byte)/trace_size)
4343

4444
# Preallocate memory
45-
headers = [BinaryTraceHeader() for _ = 1:ntraces]
45+
headers = zeros(BinaryTraceHeader, ntraces)
4646
data = Array{datatype, 2}(undef, fh.bfh.ns, ntraces)
4747
th_b2s = th_byte2sample()
4848

src/scan/scan_block.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function scan_block(buf::IO, mem_block::Int, mem_trace::Int, keys::Array{String,
66
# Calc info about this block
77
startbyte = position(buf) + chunk_start
88
ntraces_block = Int(mem_block/mem_trace)
9-
headers = [BinaryTraceHeader() for _ = 1:ntraces_block]
9+
headers = zeros(BinaryTraceHeader, ntraces_block)
1010
count = 0
1111

1212
# Read all headers and record end byte

src/scan/scan_shots.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function scan_shots!(s::IO, mem_chunk::Int, mem_trace::Int,
99
eof(s) ? (fl_eof=true) : nothing
1010
buf_size = position(seekend(buf)); seekstart(buf)
1111
ntraces = Int(floor(buf_size/mem_trace))
12-
headers = [BinaryTraceHeader() for _ = 1:ntraces]
12+
headers = zeros(BinaryTraceHeader, ntraces)
1313

1414
# Get headers from chunk
1515
th = zeros(UInt8, 240)
@@ -31,6 +31,7 @@ function scan_shots!(s::IO, mem_chunk::Int, mem_trace::Int,
3131
#combo = [[view(sx,i) view(sy,i)] for i in 1:ntraces]
3232
combo = [[sx[i] sy[i]] for i in 1:ntraces]
3333
part = delim_vector(combo, 1)
34+
3435
fl_eof ? push!(part, length(combo) + 1) : push!(part, ntraces + 1)
3536

3637
# Summarise each shot

src/types/BinaryTraceHeader.jl

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ function BinaryTraceHeader()
204204
0,0,0,0,0,0,0,0,0,0,0)
205205
end
206206

207+
Base.zeros(::Type{BinaryTraceHeader}, n::Integer) = [BinaryTraceHeader() for _=1:n]
208+
207209
function show(io::IO, bth::BinaryTraceHeader)
208210

209211
println("BinaryTraceHeader:")

src/types/SeisBlock.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function SeisBlock(data::Matrix{DT}) where {DT<:Union{Float32, IBMFloat32}}
2020
DT==Float32 ? fh.bfh.DataSampleFormat=5 : fh.bfh.DataSampleFormat=1
2121

2222
# Construct TraceHeaders
23-
traceheaders = [BinaryTraceHeader() for i in 1:ntraces]
23+
traceheaders = zeros(BinaryTraceHeader, ntraces)
2424
set_traceheader!(traceheaders, :ns, ns*ones(Int16, ntraces))
2525

2626
# Construct Block

0 commit comments

Comments
 (0)