@@ -196,7 +196,6 @@ static void flash_log_block_commit(void)
196
196
void flash_log_write (uint8_t flush_buf )
197
197
{
198
198
uint8_t * my_head = buf_head ;
199
- uint8_t * tail_copy = buf_tail ;
200
199
uint16_t chunk_size ;
201
200
202
201
HSE_sink_res sres = 0 ;
@@ -245,12 +244,12 @@ void flash_log_write(uint8_t flush_buf)
245
244
buf_tail -= BUF_SIZE ;
246
245
}
247
246
248
- /* on error, bail out and revert buffer tail to original position */
247
+ /* on error, clear the ring buffer and exit */
249
248
if (pres < 0 || sres < 0 )
250
249
{
251
250
log_compression_error ++ ;
252
251
status_flags |= ERROR_LOG_COMPRESS ;
253
- buf_tail = tail_copy ;
252
+ buf_tail = my_head ;
254
253
return ;
255
254
}
256
255
@@ -261,12 +260,12 @@ void flash_log_write(uint8_t flush_buf)
261
260
/* signal encoder that we are done */
262
261
fres = heatshrink_encoder_finish (& hse );
263
262
264
- /* on error, bail out and revert buffer tail to original position */
263
+ /* on error, clear the ring buffer and exit */
265
264
if (fres < 0 )
266
265
{
267
266
log_compression_error ++ ;
268
267
status_flags |= ERROR_LOG_COMPRESS ;
269
- buf_tail = tail_copy ;
268
+ buf_tail = my_head ;
270
269
return ;
271
270
}
272
271
@@ -282,22 +281,24 @@ void flash_log_write(uint8_t flush_buf)
282
281
283
282
/* update block length */
284
283
LogBlock .env .len += poll_sz ;
284
+
285
+ /* on block buffer overflow, clear the ring buffer and exit */
285
286
if (LogBlock .env .len >= LOG_BLOCK_DATA_SIZE )
286
287
{
287
288
log_compression_error ++ ;
288
289
status_flags |= ERROR_LOG_COMPRESS ;
289
- buf_tail = tail_copy ;
290
+ buf_tail = my_head ;
290
291
return ;
291
292
}
292
293
} while (pres == HSER_POLL_MORE );
293
294
}
294
295
295
- /* on error, bail out and revert buffer tail to original position */
296
+ /* on error, clear the ring buffer and exit */
296
297
if (pres < 0 )
297
298
{
298
299
log_compression_error ++ ;
299
300
status_flags |= ERROR_LOG_COMPRESS ;
300
- buf_tail = tail_copy ;
301
+ buf_tail = my_head ;
301
302
return ;
302
303
}
303
304
0 commit comments