comparison mercurial/cext/revlog.c @ 48770:654baf1faa52

revlog: memset whole record instead of dealing with padding This is less error-prone. Differential Revision: https://phab.mercurial-scm.org/D12177
author pacien <pacien.trangirard@pacien.net>
date Thu, 10 Feb 2022 16:20:14 +0100
parents d9a7131648a3
children 7dd5a2c0116a
comparison
equal deleted inserted replaced
48769:d9a7131648a3 48770:654baf1faa52
156 static const long entry_v2_offset_parent_2 = 28; 156 static const long entry_v2_offset_parent_2 = 28;
157 static const long entry_v2_offset_node_id = 32; 157 static const long entry_v2_offset_node_id = 32;
158 static const long entry_v2_offset_sidedata_offset = 64; 158 static const long entry_v2_offset_sidedata_offset = 64;
159 static const long entry_v2_offset_sidedata_comp_len = 72; 159 static const long entry_v2_offset_sidedata_comp_len = 72;
160 static const long entry_v2_offset_all_comp_mode = 76; 160 static const long entry_v2_offset_all_comp_mode = 76;
161 static const long entry_v2_offset_padding_start = 77; 161 /* next free offset: 77 */
162 162
163 static const char comp_mode_inline = 2; 163 static const char comp_mode_inline = 2;
164 static const char rank_unknown = -1; 164 static const char rank_unknown = -1;
165 165
166 static void raise_revlog_error(void) 166 static void raise_revlog_error(void)
601 self->added_length = new_added_length; 601 self->added_length = new_added_length;
602 } 602 }
603 rev = self->length + self->new_length; 603 rev = self->length + self->new_length;
604 data = self->added + self->entry_size * self->new_length++; 604 data = self->added + self->entry_size * self->new_length++;
605 605
606 memset(data, 0, self->entry_size);
607
606 if (self->format_version == format_v1) { 608 if (self->format_version == format_v1) {
607 putbe32(offset_flags >> 32, data + entry_v1_offset_high); 609 putbe32(offset_flags >> 32, data + entry_v1_offset_high);
608 putbe32(offset_flags & 0xffffffffU, 610 putbe32(offset_flags & 0xffffffffU,
609 data + entry_v1_offset_offset_flags); 611 data + entry_v1_offset_offset_flags);
610 putbe32(comp_len, data + entry_v1_offset_comp_len); 612 putbe32(comp_len, data + entry_v1_offset_comp_len);
613 putbe32(link_rev, data + entry_v1_offset_link_rev); 615 putbe32(link_rev, data + entry_v1_offset_link_rev);
614 putbe32(parent_1, data + entry_v1_offset_parent_1); 616 putbe32(parent_1, data + entry_v1_offset_parent_1);
615 putbe32(parent_2, data + entry_v1_offset_parent_2); 617 putbe32(parent_2, data + entry_v1_offset_parent_2);
616 memcpy(data + entry_v1_offset_node_id, c_node_id, 618 memcpy(data + entry_v1_offset_node_id, c_node_id,
617 c_node_id_len); 619 c_node_id_len);
618 /* Padding since SHA-1 is only 20 bytes for now */
619 memset(data + entry_v1_offset_node_id + c_node_id_len, 0,
620 entry_v1_offset_node_id - c_node_id_len);
621 } else if (self->format_version == format_v2) { 620 } else if (self->format_version == format_v2) {
622 putbe32(offset_flags >> 32, data + entry_v2_offset_high); 621 putbe32(offset_flags >> 32, data + entry_v2_offset_high);
623 putbe32(offset_flags & 0xffffffffU, 622 putbe32(offset_flags & 0xffffffffU,
624 data + entry_v2_offset_offset_flags); 623 data + entry_v2_offset_offset_flags);
625 putbe32(comp_len, data + entry_v2_offset_comp_len); 624 putbe32(comp_len, data + entry_v2_offset_comp_len);
628 putbe32(link_rev, data + entry_v2_offset_link_rev); 627 putbe32(link_rev, data + entry_v2_offset_link_rev);
629 putbe32(parent_1, data + entry_v2_offset_parent_1); 628 putbe32(parent_1, data + entry_v2_offset_parent_1);
630 putbe32(parent_2, data + entry_v2_offset_parent_2); 629 putbe32(parent_2, data + entry_v2_offset_parent_2);
631 memcpy(data + entry_v2_offset_node_id, c_node_id, 630 memcpy(data + entry_v2_offset_node_id, c_node_id,
632 c_node_id_len); 631 c_node_id_len);
633 /* Padding since SHA-1 is only 20 bytes for now */
634 memset(data + entry_v2_offset_node_id + c_node_id_len, 0,
635 entry_v2_offset_node_id - c_node_id_len);
636 putbe64(sidedata_offset, 632 putbe64(sidedata_offset,
637 data + entry_v2_offset_sidedata_offset); 633 data + entry_v2_offset_sidedata_offset);
638 putbe32(sidedata_comp_len, 634 putbe32(sidedata_comp_len,
639 data + entry_v2_offset_sidedata_comp_len); 635 data + entry_v2_offset_sidedata_comp_len);
640 comp_field = data_comp_mode & 3; 636 comp_field = data_comp_mode & 3;
641 comp_field = comp_field | (sidedata_comp_mode & 3) << 2; 637 comp_field = comp_field | (sidedata_comp_mode & 3) << 2;
642 data[entry_v2_offset_all_comp_mode] = comp_field; 638 data[entry_v2_offset_all_comp_mode] = comp_field;
643 /* Padding for 96 bytes alignment */
644 memset(data + entry_v2_offset_padding_start, 0,
645 self->entry_size - entry_v2_offset_padding_start);
646 } else { 639 } else {
647 raise_revlog_error(); 640 raise_revlog_error();
648 return NULL; 641 return NULL;
649 } 642 }
650 643