Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix keyword "new" warning in Cpp & OC #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions bsdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64

struct bsdiff_request
{
const uint8_t* old;
const uint8_t* oldbuffer;
int64_t oldsize;
const uint8_t* new;
const uint8_t* newbuffer;
int64_t newsize;
struct bsdiff_stream* stream;
int64_t *I;
Expand All @@ -232,7 +232,7 @@ static int bsdiff_internal(const struct bsdiff_request req)
if((V=req.stream->malloc((req.oldsize+1)*sizeof(int64_t)))==NULL) return -1;
I = req.I;

qsufsort(I,V,req.old,req.oldsize);
qsufsort(I,V,req.oldbuffer,req.oldsize);
req.stream->free(V);

buffer = req.buffer;
Expand All @@ -244,26 +244,26 @@ static int bsdiff_internal(const struct bsdiff_request req)
oldscore=0;

for(scsc=scan+=len;scan<req.newsize;scan++) {
len=search(I,req.old,req.oldsize,req.new+scan,req.newsize-scan,
len=search(I,req.oldbuffer,req.oldsize,req.newbuffer+scan,req.newsize-scan,
0,req.oldsize,&pos);

for(;scsc<scan+len;scsc++)
if((scsc+lastoffset<req.oldsize) &&
(req.old[scsc+lastoffset] == req.new[scsc]))
(req.oldbuffer[scsc+lastoffset] == req.newbuffer[scsc]))
oldscore++;

if(((len==oldscore) && (len!=0)) ||
(len>oldscore+8)) break;

if((scan+lastoffset<req.oldsize) &&
(req.old[scan+lastoffset] == req.new[scan]))
(req.oldbuffer[scan+lastoffset] == req.newbuffer[scan]))
oldscore--;
};

if((len!=oldscore) || (scan==req.newsize)) {
s=0;Sf=0;lenf=0;
for(i=0;(lastscan+i<scan)&&(lastpos+i<req.oldsize);) {
if(req.old[lastpos+i]==req.new[lastscan+i]) s++;
if(req.oldbuffer[lastpos+i]==req.newbuffer[lastscan+i]) s++;
i++;
if(s*2-i>Sf*2-lenf) { Sf=s; lenf=i; };
};
Expand All @@ -272,7 +272,7 @@ static int bsdiff_internal(const struct bsdiff_request req)
if(scan<req.newsize) {
s=0;Sb=0;
for(i=1;(scan>=lastscan+i)&&(pos>=i);i++) {
if(req.old[pos-i]==req.new[scan-i]) s++;
if(req.oldbuffer[pos-i]==req.newbuffer[scan-i]) s++;
if(s*2-i>Sb*2-lenb) { Sb=s; lenb=i; };
};
};
Expand All @@ -281,10 +281,10 @@ static int bsdiff_internal(const struct bsdiff_request req)
overlap=(lastscan+lenf)-(scan-lenb);
s=0;Ss=0;lens=0;
for(i=0;i<overlap;i++) {
if(req.new[lastscan+lenf-overlap+i]==
req.old[lastpos+lenf-overlap+i]) s++;
if(req.new[scan-lenb+i]==
req.old[pos-lenb+i]) s--;
if(req.newbuffer[lastscan+lenf-overlap+i]==
req.oldbuffer[lastpos+lenf-overlap+i]) s++;
if(req.newbuffer[scan-lenb+i]==
req.oldbuffer[pos-lenb+i]) s--;
if(s>Ss) { Ss=s; lens=i+1; };
};

Expand All @@ -302,13 +302,13 @@ static int bsdiff_internal(const struct bsdiff_request req)

/* Write diff data */
for(i=0;i<lenf;i++)
buffer[i]=req.new[lastscan+i]-req.old[lastpos+i];
buffer[i]=req.newbuffer[lastscan+i]-req.oldbuffer[lastpos+i];
if (writedata(req.stream, buffer, lenf))
return -1;

/* Write extra data */
for(i=0;i<(scan-lenb)-(lastscan+lenf);i++)
buffer[i]=req.new[lastscan+lenf+i];
buffer[i]=req.newbuffer[lastscan+lenf+i];
if (writedata(req.stream, buffer, (scan-lenb)-(lastscan+lenf)))
return -1;

Expand All @@ -321,7 +321,7 @@ static int bsdiff_internal(const struct bsdiff_request req)
return 0;
}

int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream)
int bsdiff(const uint8_t* oldbuffer, int64_t oldsize, const uint8_t* newbuffer, int64_t newsize, struct bsdiff_stream* stream)
{
int result;
struct bsdiff_request req;
Expand All @@ -335,9 +335,9 @@ int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t news
return -1;
}

req.old = old;
req.oldbuffer = oldbuffer;
req.oldsize = oldsize;
req.new = new;
req.newbuffer = newbuffer;
req.newsize = newsize;
req.stream = stream;

Expand Down
2 changes: 1 addition & 1 deletion bsdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ struct bsdiff_stream
int (*write)(struct bsdiff_stream* stream, const void* buffer, int size);
};

int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream);
int bsdiff(const uint8_t* oldbuffer, int64_t oldsize, const uint8_t* newbuffer, int64_t newsize, struct bsdiff_stream* stream);

#endif
26 changes: 13 additions & 13 deletions bspatch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*-
/*-
* Copyright 2003-2005 Colin Percival
* Copyright 2012 Matthew Endsley
* All rights reserved
Expand Down Expand Up @@ -46,7 +46,7 @@ static int64_t offtin(uint8_t *buf)
return y;
}

int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream)
int bspatch(const uint8_t* oldbuffer, int64_t oldsize, uint8_t* newbuffer, int64_t newsize, struct bspatch_stream* stream)
{
uint8_t buf[8];
int64_t oldpos,newpos;
Expand All @@ -69,13 +69,13 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize,
return -1;

/* Read diff string */
if (stream->read(stream, new + newpos, ctrl[0]))
if (stream->read(stream, newbuffer + newpos, ctrl[0]))
return -1;

/* Add old data to diff string */
for(i=0;i<ctrl[0];i++)
if((oldpos+i>=0) && (oldpos+i<oldsize))
new[newpos+i]+=old[oldpos+i];
newbuffer[newpos+i]+=oldbuffer[oldpos+i];

/* Adjust pointers */
newpos+=ctrl[0];
Expand All @@ -86,7 +86,7 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize,
return -1;

/* Read extra string */
if (stream->read(stream, new + newpos, ctrl[1]))
if (stream->read(stream, newbuffer + newpos, ctrl[1]))
return -1;

/* Adjust pointers */
Expand Down Expand Up @@ -130,7 +130,7 @@ int main(int argc,char * argv[])
int fd;
int bz2err;
uint8_t header[24];
uint8_t *old, *new;
uint8_t *oldbuffer, *newbuffer;
int64_t oldsize, newsize;
BZFILE* bz2;
struct bspatch_stream stream;
Expand Down Expand Up @@ -161,19 +161,19 @@ int main(int argc,char * argv[])
/* Close patch file and re-open it via libbzip2 at the right places */
if(((fd=open(argv[1],O_RDONLY,0))<0) ||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
((oldbuffer=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
(read(fd,old,oldsize)!=oldsize) ||
(read(fd,oldbuffer,oldsize)!=oldsize) ||
(fstat(fd, &sb)) ||
(close(fd)==-1)) err(1,"%s",argv[1]);
if((new=malloc(newsize+1))==NULL) err(1,NULL);
if((newbuffer=malloc(newsize+1))==NULL) err(1,NULL);

if (NULL == (bz2 = BZ2_bzReadOpen(&bz2err, f, 0, 0, NULL, 0)))
errx(1, "BZ2_bzReadOpen, bz2err=%d", bz2err);

stream.read = bz2_read;
stream.opaque = bz2;
if (bspatch(old, oldsize, new, newsize, &stream))
if (bspatch(oldbuffer, oldsize, newbuffer, newsize, &stream))
errx(1, "bspatch");

/* Clean up the bzip2 reads */
Expand All @@ -182,11 +182,11 @@ int main(int argc,char * argv[])

/* Write the new file */
if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,sb.st_mode))<0) ||
(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
(write(fd,newbuffer,newsize)!=newsize) || (close(fd)==-1))
err(1,"%s",argv[2]);

free(new);
free(old);
free(newbuffer);
free(oldbuffer);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion bspatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct bspatch_stream
int (*read)(const struct bspatch_stream* stream, void* buffer, int length);
};

int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream);
int bspatch(const uint8_t* oldbuffer, int64_t oldsize, uint8_t* newbuffer, int64_t newsize, struct bspatch_stream* stream);

#endif