Comparison

util/dbuffer.lua @ 11028:d7a403060946

util.dbuffer: Fix traceback when :collapse() is called on empty buffer
author Matthew Wild <mwild1@gmail.com>
date Thu, 20 Aug 2020 15:22:19 +0100
parent 10980:eaee72c7afbd
child 11045:8c6bace13229
comparison
equal deleted inserted replaced
11027:8ed6c5bdbb21 11028:d7a403060946
140 function dbuffer_methods:collapse(bytes) 140 function dbuffer_methods:collapse(bytes)
141 bytes = bytes or self._length; 141 bytes = bytes or self._length;
142 142
143 local front_chunk = self.items:peek(); 143 local front_chunk = self.items:peek();
144 144
145 if #front_chunk - self.front_consumed >= bytes then 145 if not front_chunk or #front_chunk - self.front_consumed >= bytes then
146 return; 146 return;
147 end 147 end
148 148
149 local front_chunks = { front_chunk:sub(self.front_consumed+1) }; 149 local front_chunks = { front_chunk:sub(self.front_consumed+1) };
150 local front_bytes = #front_chunks[1]; 150 local front_bytes = #front_chunks[1];