Introduce copy_bytes for writing into bytecode

Protects memcpy from nullptr sources, which triggers failures in GCC's
UB sanitizer.
This commit is contained in:
Justin Viiret
2015-11-12 15:27:11 +11:00
committed by Matthew Barr
parent cf3ddd9e88
commit 2a2576e907
5 changed files with 51 additions and 48 deletions

View File

@@ -1136,16 +1136,11 @@ aligned_unique_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
gough_dfa->length = gough_size;
/* copy in blocks */
memcpy((u8 *)gough_dfa.get() + edge_prog_offset, &edge_blocks[0],
byte_length(edge_blocks));
copy_bytes((u8 *)gough_dfa.get() + edge_prog_offset, edge_blocks);
if (top_prog_offset) {
memcpy((u8 *)gough_dfa.get() + top_prog_offset, &top_blocks[0],
byte_length(top_blocks));
}
if (!temp_blocks.empty()) {
memcpy((u8 *)gough_dfa.get() + prog_base_offset, &temp_blocks[0],
byte_length(temp_blocks));
copy_bytes((u8 *)gough_dfa.get() + top_prog_offset, top_blocks);
}
copy_bytes((u8 *)gough_dfa.get() + prog_base_offset, temp_blocks);
return gough_dfa;
}

View File

@@ -1397,8 +1397,7 @@ struct Factory {
repeat->horizon = rsi.horizon;
repeat->packedCtrlSize = rsi.packedCtrlSize;
repeat->stateSize = rsi.stateSize;
memcpy(repeat->packedFieldSizes, rsi.packedFieldSizes.data(),
byte_length(rsi.packedFieldSizes));
copy_bytes(repeat->packedFieldSizes, rsi.packedFieldSizes);
repeat->patchCount = rsi.patchCount;
repeat->patchSize = rsi.patchSize;
repeat->encodingSize = rsi.encodingSize;
@@ -1413,8 +1412,7 @@ struct Factory {
// Copy in the sparse lookup table.
if (br.type == REPEAT_SPARSE_OPTIMAL_P) {
assert(!rsi.table.empty());
memcpy(info_ptr + tableOffset, rsi.table.data(),
byte_length(rsi.table));
copy_bytes(info_ptr + tableOffset, rsi.table);
}
// Fill the tug mask.
@@ -1702,6 +1700,7 @@ struct Factory {
for (u32 i = 0; i < num_repeats; i++) {
repeatOffsets[i] = offset;
assert(repeats[i].first);
memcpy((char *)limex + offset, repeats[i].first.get(),
repeats[i].second);
offset += repeats[i].second;
@@ -1709,8 +1708,7 @@ struct Factory {
// Write repeat offset lookup table.
assert(ISALIGNED_N((char *)limex + repeatOffsetsOffset, alignof(u32)));
memcpy((char *)limex + repeatOffsetsOffset, repeatOffsets.data(),
byte_length(repeatOffsets));
copy_bytes((char *)limex + repeatOffsetsOffset, repeatOffsets);
limex->repeatOffset = repeatOffsetsOffset;
limex->repeatCount = num_repeats;
@@ -1725,8 +1723,7 @@ struct Factory {
limex->exReportOffset = exceptionReportsOffset;
assert(ISALIGNED_N((char *)limex + exceptionReportsOffset,
alignof(ReportID)));
memcpy((char *)limex + exceptionReportsOffset, reports.data(),
byte_length(reports));
copy_bytes((char *)limex + exceptionReportsOffset, reports);
}
static