Skip to content

Commit ec8cdf9

Browse files
committed
log_fcb: Init all usage of fcb_entry on stack
In several cases struct fcb_entry was not initialized before usage. In some cases it could lead to unpredictable behaviour. Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 380fb06 commit ec8cdf9

File tree

12 files changed

+20
-20
lines changed

12 files changed

+20
-20
lines changed

fs/fcb/selftest/src/testcases/fcb_test_append.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_CASE_SELF(fcb_test_append)
2222
{
2323
int rc;
2424
struct fcb *fcb;
25-
struct fcb_entry loc;
25+
struct fcb_entry loc = {};
2626
uint8_t test_data[128];
2727
int i;
2828
int j;

fs/fcb/selftest/src/testcases/fcb_test_append_fill.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_append_fill)
2323
struct fcb *fcb;
2424
int rc;
2525
int i;
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {};
2727
uint8_t test_data[128];
2828
int elem_cnts[2] = {0, 0};
2929
int aa_together_cnts[2];

fs/fcb/selftest/src/testcases/fcb_test_append_too_big.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_append_too_big)
2323
struct fcb *fcb;
2424
int rc;
2525
int len;
26-
struct fcb_entry elem_loc;
26+
struct fcb_entry elem_loc = {};
2727

2828
fcb_tc_pretest(2);
2929

fs/fcb/selftest/src/testcases/fcb_test_area_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_area_info)
2323
struct fcb *fcb;
2424
int rc;
2525
int i;
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {};
2727
uint8_t test_data[128];
2828
int elem_cnts[2] = {0, 0};
2929
int area_elems[2];

fs/fcb/selftest/src/testcases/fcb_test_last_of_n.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_last_of_n)
2323
const uint8_t ENTRIES = 5;
2424
struct fcb *fcb;
2525
int rc;
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {};
2727
struct fcb_entry areas[ENTRIES];
2828
uint8_t test_data[128];
2929
uint8_t i;

fs/fcb/selftest/src/testcases/fcb_test_multiple_scratch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_CASE_SELF(fcb_test_multiple_scratch)
2222
{
2323
struct fcb *fcb;
2424
int rc;
25-
struct fcb_entry loc;
25+
struct fcb_entry loc = {};
2626
uint8_t test_data[128];
2727
int elem_cnts[4];
2828
int idx;

fs/fcb/selftest/src/testcases/fcb_test_reset.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_reset)
2323
struct fcb *fcb;
2424
int rc;
2525
int i;
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {};
2727
uint8_t test_data[128];
2828
int var_cnt;
2929

fs/fcb/selftest/src/testcases/fcb_test_rotate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_CASE_SELF(fcb_test_rotate)
2323
struct fcb *fcb;
2424
int rc;
2525
int old_id;
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {};
2727
uint8_t test_data[128];
2828
int elem_cnts[2] = {0, 0};
2929
int cnts[2];

fs/fcb/src/fcb_area_info.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
int
2424
fcb_area_info(struct fcb *fcb, struct flash_area *fa, int *elemsp, int *bytesp)
2525
{
26-
struct fcb_entry loc;
26+
struct fcb_entry loc = {
27+
.fe_area = fa,
28+
.fe_elem_off = 0,
29+
};
2730
int rc;
2831
int elems = 0;
2932
int bytes = 0;
3033

31-
loc.fe_area = fa;
32-
loc.fe_elem_off = 0;
33-
3434
while (1) {
3535
rc = fcb_getnext(fcb, &loc);
3636
if (rc) {

hw/drivers/flash/enc_flash/selftest/src/testcases/enc_flash_fcb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST_CASE_SELF(enc_flash_test_fcb)
3434
{
3535
int rc;
3636
struct flash_area *fa;
37-
struct fcb_entry loc;
37+
struct fcb_entry loc = {};
3838
struct fcb fcb;
3939
int i;
4040
char *writedata = "foobartest";

sys/config/src/config_fcb.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ conf_fcb_compress_internal(struct fcb *fcb,
169169
int rc;
170170
char buf1[CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32];
171171
char buf2[CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32];
172-
struct fcb_entry loc1;
173-
struct fcb_entry loc2;
172+
struct fcb_entry loc1 = {};
173+
struct fcb_entry loc2 = {};
174174
char *name1, *val1;
175175
char *name2, *val2;
176176
int copy;
@@ -248,7 +248,7 @@ conf_fcb_append(struct fcb *fcb, char *buf, int len)
248248
{
249249
int rc;
250250
int i;
251-
struct fcb_entry loc;
251+
struct fcb_entry loc = {};
252252

253253
for (i = 0; i < 10; i++) {
254254
rc = fcb_append(fcb, len, &loc);

sys/log/full/src/log_fcb.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
305305
uint8_t buf[LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN +
306306
LOG_FCB_MAX_ALIGN - 1];
307307
struct fcb *fcb;
308-
struct fcb_entry loc;
308+
struct fcb_entry loc = {};
309309
struct fcb_log *fcb_log;
310310
const uint8_t *u8p;
311311
int hdr_alignment;
@@ -412,7 +412,7 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
412412
struct os_mbuf *om)
413413
{
414414
struct fcb *fcb;
415-
struct fcb_entry loc;
415+
struct fcb_entry loc = {};
416416
struct fcb_log *fcb_log;
417417
int len;
418418
int rc;
@@ -578,7 +578,7 @@ log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
578578
{
579579
struct fcb *fcb;
580580
struct fcb_log *fcb_log;
581-
struct fcb_entry loc;
581+
struct fcb_entry loc = {};
582582
struct flash_area *fap;
583583
int rc;
584584
struct fcb_entry_cache cache;
@@ -932,7 +932,7 @@ log_fcb_rtr_erase(struct log *log)
932932
struct fcb fcb_scratch;
933933
struct fcb *fcb;
934934
const struct flash_area *ptr;
935-
struct fcb_entry entry;
935+
struct fcb_entry entry = {};
936936
int rc;
937937
struct flash_area sector;
938938

0 commit comments

Comments
 (0)