runtime error: slice bounds out of range
njflove opened this issue · comments
njflove commented
Line 1572 in 7e59db9
My code looks like this:
func (e *encoder) Write(p []byte) (n int, err error) {
lenght := len(p)
current := 0
for lenght != 0 {
next := BLOCK_SIZE - len(e.cache)
if next > lenght {
next = lenght
}
e.cache = append(e.cache, p[current:current+next]...)
// If the cache is full, the Flush() method will be called to actually write the cache to writers.
if len(e.cache) == BLOCK_SIZE {
e.Flush()
}
current += next
lenght -= next
}
return len(p), nil
}
func (rsp *RSPutStream) Commit(success bool) error {
rsp.Flush()
for i := range rsp.writers {
err := rsp.writers[i].(*objectstream.TempPutStream).Commit(success)
if err != nil {
return err
}
}
return nil
}
The p argument to the Write method has a length of 729, and on the last call to Commit (true), an error is reported slice bounds out of range [780:779]
njflove commented
If use e.ache =p, it's can be successfully executed.
I'm not sure if it's 'e.cache = append(e.cache, p[current:current+next]...) 'changed the reason for e.ache.cap, after executing the above code, e.ache.cap = 768.
Klaus Post commented
(edited your initial post for formatting)
Klaus Post commented
Fixed and released.