This is an automated email from the ASF dual-hosted git repository. marko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 06474c065f84d56b29c67998421fe717f7f80fb8 Author: Marko Kiiskila <ma...@apache.org> AuthorDate: Wed Aug 28 10:34:11 2019 +0300 sys/log/full; check if log index is > last entry before starting walk of FCB2 area. --- sys/log/full/src/log_fcb2.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c index 590424c..9e5c4d1 100644 --- a/sys/log/full/src/log_fcb2.c +++ b/sys/log/full/src/log_fcb2.c @@ -67,9 +67,9 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset, fcb_log = log->l_arg; fcb = &fcb_log->fl_fcb; - /* Attempt to read the first entry. If this fails, the FCB is empty. */ - memset(out_entry, 0, sizeof *out_entry); - rc = fcb_getnext(fcb, out_entry); + /* Attempt to read the last entry. If this fails, the FCB is empty. */ + memset(out_entry, 0, sizeof(*out_entry)); + rc = fcb_getprev(fcb, out_entry); if (rc == FCB_ERR_NOVAR) { return SYS_ENOENT; } else if (rc != 0) { @@ -77,25 +77,31 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset, } /* - * if timestamp for request is < 0, return last log entry + * if timestamp for request is < 0, return last log entry (already read). */ if (log_offset->lo_ts < 0) { - *out_entry = fcb->f_active; return 0; } -#if 0 /* XXXX */ /* If the requested index is beyond the end of the log, there is nothing to * retrieve. */ - rc = log_read_hdr(log, &fcb->f_active, &hdr); + rc = log_read_hdr(log, out_entry, &hdr); if (rc != 0) { return rc; } if (log_offset->lo_index > hdr.ue_index) { return SYS_ENOENT; } -#endif + + /* + * Start from beginning. + */ + memset(out_entry, 0, sizeof(*out_entry)); + rc = fcb_getnext(fcb, out_entry); + if (rc != 0) { + return SYS_EUNKNOWN; + } #if MYNEWT_VAL(LOG_FCB_BOOKMARKS) bmark = fcb_log_closest_bmark(fcb_log, log_offset->lo_index); if (bmark != NULL) {