Skip to content

Commit 6f6a32e

Browse files
authored
Merge pull request #53 from struct/11_21_remove_memcpyset
remove unnecessary calls to memcpy and memset
2 parents 1ff4cd3 + fedbb8a commit 6f6a32e

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/iso_alloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ INTERNAL_HIDDEN iso_alloc_zone *_iso_new_zone(size_t size, bool internal) {
705705
MASK_ZONE_PTRS(new_zone);
706706

707707
/* The lookup table is never used for custom zones */
708-
if(internal == true) {
708+
if(LIKELY(internal == true)) {
709709
/* If no other zones of this size exist then set the
710710
* index in the zone lookup table to its index */
711711
if(_zone_lookup_table[size] == 0) {
@@ -1094,7 +1094,7 @@ INTERNAL_HIDDEN void *_iso_alloc_bitslot_from_zone(bit_slot_t bitslot, iso_alloc
10941094
#if !ENABLE_ASAN && !DISABLE_CANARY
10951095
if((GET_BIT(b, (which_bit + 1))) == 1) {
10961096
check_canary(zone, p);
1097-
memset(p, 0x0, CANARY_SIZE);
1097+
*(uint64_t *) p = 0x0;
10981098
}
10991099
#endif
11001100

@@ -1447,9 +1447,9 @@ INTERNAL_HIDDEN INLINE void check_big_canary(iso_alloc_big_zone *big) {
14471447
* unbounded string reads from leaking it */
14481448
INTERNAL_HIDDEN INLINE void write_canary(iso_alloc_zone *zone, void *p) {
14491449
uint64_t canary = (zone->canary_secret ^ (uint64_t) p) & CANARY_VALIDATE_MASK;
1450-
memcpy(p, &canary, CANARY_SIZE);
1450+
*(uint64_t *)p = canary;
14511451
p += (zone->chunk_size - sizeof(uint64_t));
1452-
memcpy(p, &canary, CANARY_SIZE);
1452+
*(uint64_t *)p = canary;
14531453
}
14541454

14551455
/* Verify the canary value in an allocation */

src/iso_alloc_sanity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ INTERNAL_HIDDEN INLINE void write_sanity_canary(void *p) {
119119
uint64_t canary = (_sanity_canary & SANITY_CANARY_VALIDATE_MASK);
120120

121121
for(int32_t i = 0; i < (g_page_size / sizeof(uint64_t)); i++) {
122-
memcpy(p, &canary, SANITY_CANARY_SIZE);
122+
*(uint64_t *) p = canary;
123123
p += sizeof(uint64_t);
124124
}
125125
}

0 commit comments

Comments
 (0)