summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-02-21 04:18:46 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-02-21 04:18:46 +0000
commitab45f2fa73b2433f84cc32b44eb36b69c1da81e8 (patch)
tree7f131c90689cd00021cdaf65522b3058ada55b76
parent52d8fcb212a34f22bb934155501ca2e7ebbc6b45 (diff)
Simplify cvs_buf_differ(). Also cvs_buf_differ(), a comparison
function, should not do any resource freeing. OK joris@.
-rw-r--r--usr.bin/cvs/buf.c25
-rw-r--r--usr.bin/cvs/buf.h4
-rw-r--r--usr.bin/cvs/file.c5
-rw-r--r--usr.bin/cvs/import.c4
4 files changed, 12 insertions, 26 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c
index f4fbb61c555..79ee048e037 100644
--- a/usr.bin/cvs/buf.c
+++ b/usr.bin/cvs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.58 2007/02/19 11:40:00 otto Exp $ */
+/* $OpenBSD: buf.c,v 1.59 2007/02/21 04:18:45 ray Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -408,27 +408,10 @@ cvs_buf_peek(BUF *b, size_t off)
}
int
-cvs_buf_differ(BUF *b1, BUF *b2)
+cvs_buf_differ(const BUF *b1, const BUF *b2)
{
- char *c1, *c2;
- int l1, l2, len, ret;
-
- l1 = cvs_buf_len(b1);
- l2 = cvs_buf_len(b2);
- len = MIN(l1, l2);
-
- if (l1 != l2)
+ if (b1->cb_len != b2->cb_len)
return (1);
- c1 = cvs_buf_release(b1);
- c2 = cvs_buf_release(b2);
-
- ret = memcmp(c1, c2, len);
-
- if (c1 != NULL)
- xfree(c1);
- if (c2 != NULL)
- xfree(c2);
-
- return (ret);
+ return (memcmp(b1->cb_buf, b2->cb_buf, b1->cb_len));
}
diff --git a/usr.bin/cvs/buf.h b/usr.bin/cvs/buf.h
index 91b976cf7bd..483c8b5f696 100644
--- a/usr.bin/cvs/buf.h
+++ b/usr.bin/cvs/buf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.h,v 1.20 2007/02/19 11:40:00 otto Exp $ */
+/* $OpenBSD: buf.h,v 1.21 2007/02/21 04:18:45 ray Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -46,7 +46,7 @@ void cvs_buf_putc(BUF *, int);
size_t cvs_buf_len(BUF *);
int cvs_buf_write_fd(BUF *, int);
int cvs_buf_write(BUF *, const char *, mode_t);
-int cvs_buf_differ(BUF *, BUF *);
+int cvs_buf_differ(const BUF *, const BUF *);
void cvs_buf_write_stmp(BUF *, char *, struct timeval *);
ssize_t cvs_buf_copy(BUF *, size_t, void *, size_t);
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index e04974736c6..34144a5ddbc 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.187 2007/02/19 11:40:00 otto Exp $ */
+/* $OpenBSD: file.c,v 1.188 2007/02/21 04:18:45 ray Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
@@ -669,11 +669,12 @@ cvs_file_classify(struct cvs_file *cf, const char *tag)
if (b2 == NULL)
fatal("failed to get file content for comparison");
- /* b1 and b2 get released in cvs_buf_differ */
if (cvs_buf_differ(b1, b2))
ismodified = 1;
else
ismodified = 0;
+ cvs_buf_free(b1);
+ cvs_buf_free(b2);
}
if (cf->file_rcs != NULL && cf->file_rcsrev != NULL) {
diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c
index fbe1e3d3d03..de47d7ec882 100644
--- a/usr.bin/cvs/import.c
+++ b/usr.bin/cvs/import.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: import.c,v 1.70 2007/02/17 18:23:43 xsa Exp $ */
+/* $OpenBSD: import.c,v 1.71 2007/02/21 04:18:45 ray Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -303,6 +303,8 @@ import_update(struct cvs_file *cf)
cf->file_path);
ret = cvs_buf_differ(b1, b2);
+ cvs_buf_free(b1);
+ cvs_buf_free(b2);
if (ret == 0) {
import_tag(cf, brev, rev);
rcsnum_free(brev);