Skip to content

Commit 16e2dd8

Browse files
cosmo0920edsiper
authored andcommitted
in_syslog: tests: Split declaration and applying values
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 4789437 commit 16e2dd8

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

tests/runtime/in_syslog.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,14 @@ static size_t build_octet_frame(char *out, size_t outsz,
326326
const char *msg, int add_lf)
327327
{
328328
char tmp[2048];
329-
size_t mlen = rstrip_nl_copy(tmp, sizeof(tmp), msg);
329+
size_t mlen = 0;
330330
char hdr[64];
331-
int hlen = snprintf(hdr, sizeof(hdr), "%zu ", mlen);
332-
size_t need = (size_t)hlen + mlen + (add_lf ? 1 : 0);
331+
int hlen = 0;
332+
size_t need = 0;
333+
334+
mlen = rstrip_nl_copy(tmp, sizeof(tmp), msg);
335+
hlen = snprintf(hdr, sizeof(hdr), "%zu ", mlen);
336+
need = (size_t)hlen + mlen + (add_lf ? 1 : 0);
333337

334338
if (need + 1 > outsz) {
335339
/* truncate conservatively if buffer too small (shouldn't happen in tests) */
@@ -340,7 +344,7 @@ static size_t build_octet_frame(char *out, size_t outsz,
340344
}
341345
}
342346

343-
memcpy(out, hdr, (size_t)hlen);
347+
memcpy(out, hdr, hlen);
344348
memcpy(out + hlen, tmp, mlen);
345349
if (add_lf) {
346350
out[hlen + mlen] = '\n';
@@ -1072,8 +1076,9 @@ void flb_test_syslog_tcp_octet_counting()
10721076
};
10731077

10741078
char frame[4096];
1075-
size_t fsize = build_octet_frame(frame, sizeof(frame), RFC5424_EXAMPLE_1, /*add_lf=*/0);
1079+
size_t fsize = 0;
10761080

1081+
fsize = build_octet_frame(frame, sizeof(frame), RFC5424_EXAMPLE_1, /*add_lf=*/0);
10771082
clear_output_num();
10781083
cb_data.cb = cb_check_json_str_list;
10791084
cb_data.data = &expected;
@@ -1134,8 +1139,9 @@ void flb_test_syslog_tcp_octet_counting_lf()
11341139
};
11351140

11361141
char frame[4096];
1137-
size_t fsize = build_octet_frame(frame, sizeof(frame), RFC5424_EXAMPLE_1, /*add_lf=*/1);
1142+
size_t fsize = 0;
11381143

1144+
fsize = build_octet_frame(frame, sizeof(frame), RFC5424_EXAMPLE_1, /*add_lf=*/1);
11391145
clear_output_num();
11401146
cb_data.cb = cb_check_json_str_list;
11411147
cb_data.data = &expected;
@@ -1196,9 +1202,12 @@ void flb_test_syslog_tcp_octet_counting_fragmented()
11961202
};
11971203

11981204
char msg[2048];
1199-
size_t mlen = rstrip_nl_copy(msg, sizeof(msg), RFC5424_EXAMPLE_1);
1205+
size_t mlen = 0;
12001206
char hdr[64];
1201-
int hlen = snprintf(hdr, sizeof(hdr), "%zu ", mlen);
1207+
int hlen = 0;
1208+
1209+
mlen = rstrip_nl_copy(msg, sizeof(msg), RFC5424_EXAMPLE_1);
1210+
hlen = snprintf(hdr, sizeof(hdr), "%zu ", mlen);
12021211

12031212
clear_output_num();
12041213
cb_data.cb = cb_check_json_str_list;
@@ -1272,9 +1281,11 @@ void flb_test_syslog_tcp_octet_counting_multi()
12721281
};
12731282

12741283
char frames[8192];
1275-
size_t fsize = build_two_frames(frames, sizeof(frames),
1276-
RFC5424_EXAMPLE_1, RFC5424_EXAMPLE_1,
1277-
/*add_lf_for_each=*/0);
1284+
size_t fsize = 0;
1285+
1286+
fsize = build_two_frames(frames, sizeof(frames),
1287+
RFC5424_EXAMPLE_1, RFC5424_EXAMPLE_1,
1288+
/*add_lf_for_each=*/0);
12781289

12791290
clear_output_num();
12801291
cb_data.cb = cb_check_json_str_list;

0 commit comments

Comments
 (0)