Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit e27563e

Browse files
committed
Rename oldsize->old_size and newsize->new_size
To align better with variable renamings in the forthcoming commit, rename the two variables indicating size of the old and new files first. Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
1 parent e0e8bcd commit e27563e

File tree

3 files changed

+95
-95
lines changed

3 files changed

+95
-95
lines changed

src/diff.c

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ static int bsdiff_fulldl;
7474
#undef MIN
7575
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
7676

77-
static int64_t matchlen(u_char *old, int64_t oldsize, u_char *new,
78-
int64_t newsize)
77+
static int64_t matchlen(u_char *old, int64_t old_size, u_char *new,
78+
int64_t new_size)
7979
{
8080
int64_t i;
8181

82-
for (i = 0; (i < oldsize) && (i < newsize); i++) {
82+
for (i = 0; (i < old_size) && (i < new_size); i++) {
8383
if (old[i] != new[i]) {
8484
break;
8585
}
@@ -96,27 +96,27 @@ static int64_t matchlen(u_char *old, int64_t oldsize, u_char *new,
9696
* updated to the position of the match within OLD, and MAX_LEN is set to the
9797
* match length.
9898
*/
99-
static void search(int64_t *I, u_char *old, int64_t oldsize,
100-
u_char *new, int64_t newsize, int64_t st, int64_t en,
99+
static void search(int64_t *I, u_char *old, int64_t old_size,
100+
u_char *new, int64_t new_size, int64_t st, int64_t en,
101101
int64_t *pos, int64_t *max_len)
102102
{
103103
int64_t x, y;
104104

105105
/* Initialize max_len for the binary search */
106-
if (st == 0 && en == oldsize) {
107-
*max_len = matchlen(old, oldsize, new, newsize);
106+
if (st == 0 && en == old_size) {
107+
*max_len = matchlen(old, old_size, new, new_size);
108108
*pos = I[st];
109109
}
110110

111111
/* The binary search terminates here when "en" and "st" are adjacent
112112
* indices in the suffix-sorted array. */
113113
if (en - st < 2) {
114-
x = matchlen(old + I[st], oldsize - I[st], new, newsize);
114+
x = matchlen(old + I[st], old_size - I[st], new, new_size);
115115
if (x > *max_len) {
116116
*max_len = x;
117117
*pos = I[st];
118118
}
119-
y = matchlen(old + I[en], oldsize - I[en], new, newsize);
119+
y = matchlen(old + I[en], old_size - I[en], new, new_size);
120120
if (y > *max_len) {
121121
*max_len = y;
122122
*pos = I[en];
@@ -127,7 +127,7 @@ static void search(int64_t *I, u_char *old, int64_t oldsize,
127127

128128
x = st + (en - st) / 2;
129129

130-
int64_t length = MIN(oldsize - I[x], newsize);
130+
int64_t length = MIN(old_size - I[x], new_size);
131131
u_char *oldoffset = old + I[x];
132132

133133
/* This match *could* be the longest one, so check for that here */
@@ -139,9 +139,9 @@ static void search(int64_t *I, u_char *old, int64_t oldsize,
139139

140140
/* Determine how to continue the binary search */
141141
if (memcmp(oldoffset, new, length) < 0) {
142-
return search(I, old, oldsize, new, newsize, x, en, pos, max_len);
142+
return search(I, old, old_size, new, new_size, x, en, pos, max_len);
143143
} else {
144-
return search(I, old, oldsize, new, newsize, st, x, pos, max_len);
144+
return search(I, old, old_size, new, new_size, st, x, pos, max_len);
145145
}
146146
}
147147

@@ -386,7 +386,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
386386
{
387387
int fd, efd;
388388
u_char *old_data, *new_data;
389-
int64_t oldsize, newsize;
389+
int64_t old_size, new_size;
390390
int64_t *I, *V;
391391
int64_t scan;
392392
int64_t pos = 0;
@@ -439,12 +439,12 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
439439
return -1;
440440
}
441441

442-
oldsize = old_stat.st_size;
442+
old_size = old_stat.st_size;
443443

444444
/* We may start with an empty file, if so, just mark it for full download
445445
* to throw into the pack. In the case that newfile is <200, it will quit
446-
* and ask for fulldownload, so we only need to check oldsize */
447-
if (oldsize == 0) {
446+
* and ask for fulldownload, so we only need to check old_size */
447+
if (old_size == 0) {
448448
memset(&small_header, 0, sizeof(struct header_v21));
449449
memcpy(&small_header.magic, BSDIFF_HDR_FULLDL, 8);
450450

@@ -471,9 +471,9 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
471471
/* TODO: investigate why this needs to be +1 to not overrun; coverity complains
472472
* that we overrun old_data when we calculate differences otherwise. Tenatively,
473473
* since this is used in qsufsort, it may need to be +1 like I and V because of
474-
* a sentinel byte when sorting. However, newsize does not cause any overruns
474+
* a sentinel byte when sorting. However, new_size does not cause any overruns
475475
* when created with the regular file size */
476-
old_data = mmap(NULL, oldsize + 1, PROT_READ, MAP_SHARED, fd, 0);
476+
old_data = mmap(NULL, old_size + 1, PROT_READ, MAP_SHARED, fd, 0);
477477
close(fd);
478478

479479
if (old_data == MAP_FAILED) {
@@ -483,19 +483,19 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
483483

484484
/* These arrays are size + 1 because suffix sort needs space for the
485485
* data + 1 sentinel element to actually do the sorting. Not because
486-
* oldsize might be 0. */
487-
if ((I = malloc((oldsize + 1) * sizeof(int64_t))) == NULL) {
488-
munmap(old_data, oldsize);
486+
* old_size might be 0. */
487+
if ((I = malloc((old_size + 1) * sizeof(int64_t))) == NULL) {
488+
munmap(old_data, old_size);
489489
return -1;
490490
}
491-
if ((V = malloc((oldsize + 1) * sizeof(int64_t))) == NULL) {
492-
munmap(old_data, oldsize);
491+
if ((V = malloc((old_size + 1) * sizeof(int64_t))) == NULL) {
492+
munmap(old_data, old_size);
493493
free(I);
494494
return -1;
495495
}
496496

497-
if (qsufsort(I, V, old_data, oldsize) != 0) {
498-
munmap(old_data, oldsize);
497+
if (qsufsort(I, V, old_data, old_size) != 0) {
498+
munmap(old_data, old_size);
499499
free(I);
500500
free(V);
501501
return -1;
@@ -504,19 +504,19 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
504504
free(V);
505505

506506
if ((fd = open(new_filename, O_RDONLY, 0)) < 0) {
507-
munmap(old_data, oldsize);
507+
munmap(old_data, old_size);
508508
free(I);
509509
return -1;
510510
}
511511

512512
if (fstat(fd, &new_stat) != 0) {
513-
munmap(old_data, oldsize);
513+
munmap(old_data, old_size);
514514
free(I);
515515
close(fd);
516516
return -1;
517517
}
518518

519-
newsize = new_stat.st_size;
519+
new_size = new_stat.st_size;
520520

521521
/* Note: testing this to see how diffs between small files affect
522522
* updates. Small files seem to cause some problems between certain
@@ -526,76 +526,76 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
526526
* the "is bsdiff < 90% of newfile size" check that would otherwise
527527
* be performed later on.
528528
*/
529-
if (newsize < 200) {
529+
if (new_size < 200) {
530530
memset(&small_header, 0, sizeof(struct header_v21));
531531
memcpy(&small_header.magic, BSDIFF_HDR_FULLDL, 8);
532532

533533
efd = open(delta_filename, O_CREAT | O_EXCL | O_WRONLY, 00644);
534534
if (efd < 0) {
535535
close(fd);
536-
munmap(old_data, oldsize);
536+
munmap(old_data, old_size);
537537
free(I);
538538
return -1;
539539
}
540540
if ((pf = fdopen(efd, "w")) == NULL) {
541541
close(efd);
542542
close(fd);
543-
munmap(old_data, oldsize);
543+
munmap(old_data, old_size);
544544
free(I);
545545
return -1;
546546
}
547547
if (fwrite(&small_header, 8, 1, pf) != 1) {
548548
fclose(pf);
549549
close(fd);
550-
munmap(old_data, oldsize);
550+
munmap(old_data, old_size);
551551

552552
free(I);
553553
return -1;
554554
}
555555
fclose(pf);
556556
close(fd);
557-
munmap(old_data, oldsize);
557+
munmap(old_data, old_size);
558558
free(I);
559559
return 1;
560560
}
561561

562-
if ((new_data = malloc(newsize)) == NULL) {
562+
if ((new_data = malloc(new_size)) == NULL) {
563563
close(fd);
564-
munmap(old_data, oldsize);
564+
munmap(old_data, old_size);
565565
free(I);
566566
return -1;
567567
}
568568

569-
if (pread(fd, new_data, newsize, 0) != newsize) {
569+
if (pread(fd, new_data, new_size, 0) != new_size) {
570570
close(fd);
571-
munmap(old_data, oldsize);
571+
munmap(old_data, old_size);
572572
free(new_data);
573573
free(I);
574574
return -1;
575575
}
576576
if (close(fd) == -1) {
577-
munmap(old_data, oldsize);
577+
munmap(old_data, old_size);
578578
free(new_data);
579579
free(I);
580580
return -1;
581581
}
582582

583583
/* we can write 3 8 byte tupples extra, so allocate some headroom */
584-
if ((cb = malloc(newsize + 25)) == NULL) {
585-
munmap(old_data, oldsize);
584+
if ((cb = malloc(new_size + 25)) == NULL) {
585+
munmap(old_data, old_size);
586586
free(new_data);
587587
free(I);
588588
return -1;
589589
}
590-
if ((db = malloc(newsize + 25)) == NULL) {
591-
munmap(old_data, oldsize);
590+
if ((db = malloc(new_size + 25)) == NULL) {
591+
munmap(old_data, old_size);
592592
free(new_data);
593593
free(cb);
594594
free(I);
595595
return -1;
596596
}
597-
if ((eb = malloc(newsize + 25)) == NULL) {
598-
munmap(old_data, oldsize);
597+
if ((eb = malloc(new_size + 25)) == NULL) {
598+
munmap(old_data, old_size);
599599
free(new_data);
600600
free(cb);
601601
free(db);
@@ -612,15 +612,15 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
612612
lastscan = 0;
613613
lastpos = 0;
614614
lastoffset = 0;
615-
while (scan < newsize) {
615+
while (scan < new_size) {
616616
oldscore = 0;
617617

618-
for (scsc = scan += len; scan < newsize; scan++) {
619-
search(I, old_data, oldsize, new_data + scan, newsize - scan,
620-
0, oldsize, &pos, &len);
618+
for (scsc = scan += len; scan < new_size; scan++) {
619+
search(I, old_data, old_size, new_data + scan, new_size - scan,
620+
0, old_size, &pos, &len);
621621

622622
for (; scsc < scan + len; scsc++) {
623-
if ((scsc + lastoffset < oldsize) &&
623+
if ((scsc + lastoffset < old_size) &&
624624
(old_data[scsc + lastoffset] == new_data[scsc])) {
625625
oldscore++;
626626
}
@@ -631,18 +631,18 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
631631
break;
632632
}
633633

634-
if ((scan + lastoffset < oldsize) &&
634+
if ((scan + lastoffset < old_size) &&
635635
(old_data[scan + lastoffset] == new_data[scan])) {
636636
oldscore--;
637637
}
638638
}
639639

640-
if ((len != oldscore) || (scan == newsize)) {
640+
if ((len != oldscore) || (scan == new_size)) {
641641
s = 0;
642642
Sf = 0;
643643
lenf = 0;
644644
for (i = 0;
645-
(lastscan + i < scan) && (lastpos + i < oldsize);) {
645+
(lastscan + i < scan) && (lastpos + i < old_size);) {
646646
if (old_data[lastpos + i] == new_data[lastscan + i]) {
647647
s++;
648648
}
@@ -654,7 +654,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
654654
}
655655

656656
lenb = 0;
657-
if (scan < newsize) {
657+
if (scan < new_size) {
658658
s = 0;
659659
Sb = 0;
660660
for (i = 1;
@@ -707,8 +707,8 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
707707

708708
/* checking for control block overflow...
709709
* See regression test #15 for an example */
710-
if ((int64_t)(cblen + 24) > (newsize + 25)) {
711-
munmap(old_data, oldsize);
710+
if ((int64_t)(cblen + 24) > (new_size + 25)) {
711+
munmap(old_data, old_size);
712712
free(new_data);
713713
free(cb);
714714
free(db);
@@ -766,8 +766,8 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
766766
small_header.control_length = cblen;
767767
small_header.diff_length = dblen;
768768
small_header.extra_length = eblen;
769-
small_header.old_file_length = oldsize;
770-
small_header.new_file_length = newsize;
769+
small_header.old_file_length = old_size;
770+
small_header.new_file_length = new_size;
771771
small_header.file_mode = new_stat.st_mode;
772772
small_header.file_owner = new_stat.st_uid;
773773
small_header.file_group = new_stat.st_gid;
@@ -777,7 +777,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
777777
eblock_set_enc(&small_header.encoding, e_enc);
778778
encodings = small_header.encoding;
779779

780-
if ((first_block + cblen + dblen + eblen > 0.90 * newsize) && (enc != BSDIFF_ENC_NONE)) { /* tune */
780+
if ((first_block + cblen + dblen + eblen > 0.90 * new_size) && (enc != BSDIFF_ENC_NONE)) { /* tune */
781781
memcpy(&small_header.magic, BSDIFF_HDR_FULLDL, 8);
782782
ret = 1;
783783
if (fwrite(&small_header, 8, 1, pf) != 1) {
@@ -805,8 +805,8 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
805805
large_header.control_length = cblen;
806806
large_header.diff_length = dblen;
807807
large_header.extra_length = eblen;
808-
large_header.old_file_length = oldsize;
809-
large_header.new_file_length = newsize;
808+
large_header.old_file_length = old_size;
809+
large_header.new_file_length = new_size;
810810
large_header.file_mode = new_stat.st_mode;
811811
large_header.file_owner = new_stat.st_uid;
812812
large_header.file_group = new_stat.st_gid;
@@ -816,7 +816,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
816816
eblock_set_enc(&large_header.encoding, e_enc);
817817
encodings = large_header.encoding;
818818

819-
if ((first_block + cblen + dblen + eblen > 0.90 * newsize) && (enc != BSDIFF_ENC_NONE)) { /* tune */
819+
if ((first_block + cblen + dblen + eblen > 0.90 * new_size) && (enc != BSDIFF_ENC_NONE)) { /* tune */
820820
memcpy(&large_header.magic, BSDIFF_HDR_FULLDL, 8);
821821
ret = 1;
822822
if (fwrite(&large_header, 8, 1, pf) != 1) {
@@ -847,7 +847,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
847847
}
848848

849849
bsdiff_files++;
850-
bsdiff_newbytes += newsize;
850+
bsdiff_newbytes += new_size;
851851
bsdiff_outputbytes += first_block + cblen + dblen + eblen;
852852

853853
if (cblock_get_enc(encodings) == BSDIFF_ENC_NONE) {
@@ -901,7 +901,7 @@ int make_bsdiff_delta(char *old_filename, char *new_filename, char *delta_filena
901901
}
902902
fulldl_free:
903903
/* Free the memory we used */
904-
munmap(old_data, oldsize);
904+
munmap(old_data, old_size);
905905
free(new_data);
906906
free(cb);
907907
free(db);

0 commit comments

Comments
 (0)