mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
fix param_export: off-by-one buffer size
In rare circumstances, the buffer size was too small by 1 byte, leading to a param export failure. And leading to a reset of all params! This could only happen when the last saved param was a float. Also the realloc_ok initialization is not needed.
This commit is contained in:
@@ -1035,7 +1035,6 @@ param_export(int fd, bool only_unsaved)
|
||||
int result = -1;
|
||||
|
||||
struct bson_encoder_s encoder;
|
||||
encoder.realloc_ok = 0;
|
||||
|
||||
int shutdown_lock_ret = px4_shutdown_lock();
|
||||
|
||||
@@ -1072,9 +1071,9 @@ param_export(int fd, bool only_unsaved)
|
||||
const size_t size = param_size(s->param);
|
||||
|
||||
// check remaining buffer size and commit to disk
|
||||
// total size = name + param size + bson header + bson end
|
||||
// total size = strlen(name) + 1 (null char) + param size + 1 (bson header) + 1 (bson end)
|
||||
// size is doubled (floats saved as doubles)
|
||||
const size_t total_size = strlen(name) + 2 * size + 2;
|
||||
const size_t total_size = strlen(name) + 2 * size + 3;
|
||||
|
||||
if (encoder.bufpos > encoder.bufsize - total_size) {
|
||||
// write buffer to disk and continue
|
||||
|
||||
Reference in New Issue
Block a user