Skip to content

Commit 01cf1cb

Browse files
committed
MDEV-7850: Optimize Query_log_event::begin_event()
* Use bfill() to pad a Query_log_event (from GTID event) instead of a loop. * Add error conditions Co-author: Monty <monty@mariadb.org>
1 parent 5217d86 commit 01cf1cb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sql/log_event.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ Query_log_event::begin_event(String *packet, ulong ev_offset,
19471947
uchar *p= (uchar *)packet->ptr() + ev_offset;
19481948
uchar *q= p + LOG_EVENT_HEADER_LEN;
19491949
size_t data_len= packet->length() - ev_offset;
1950-
size_t dummy_bytes;
1950+
uint dummy_bytes;
19511951
uint16 flags;
19521952

19531953
if (checksum_alg == BINLOG_CHECKSUM_ALG_CRC32)
@@ -1975,10 +1975,14 @@ Query_log_event::begin_event(String *packet, ulong ev_offset,
19751975
DUMMY value, and will skip the rest of the status vars section.
19761976
*/
19771977
DBUG_ASSERT(data_len >= LOG_EVENT_HEADER_LEN + GTID_HEADER_LEN);
1978-
dummy_bytes= data_len - (LOG_EVENT_HEADER_LEN + GTID_HEADER_LEN);
1978+
if (data_len < LOG_EVENT_HEADER_LEN + GTID_HEADER_LEN)
1979+
return 1;
1980+
DBUG_ASSERT(std::numeric_limits<uint16>::max() >=
1981+
(data_len - (LOG_EVENT_HEADER_LEN + GTID_HEADER_LEN)));
1982+
dummy_bytes=
1983+
static_cast<uint>(data_len - (LOG_EVENT_HEADER_LEN + GTID_HEADER_LEN));
19791984
int2store(q + Q_STATUS_VARS_LEN_OFFSET, dummy_bytes);
1980-
for (size_t i= 0; i < dummy_bytes; i++)
1981-
q[Q_DATA_OFFSET + i]= Q_DUMMY;
1985+
bfill(&q[Q_DATA_OFFSET], dummy_bytes, Q_DUMMY);
19821986
q[Q_DATA_OFFSET + dummy_bytes]= 0; /* Zero terminator for empty db */
19831987
q+= Q_DATA_OFFSET + dummy_bytes + 1;
19841988

0 commit comments

Comments
 (0)