diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-04-17 12:03:20 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-04-17 12:03:20 +0000 |
commit | 92fe60d3b357050bf6f284775eca285674b0322d (patch) | |
tree | 3ce524b30bb55a73496e8fccfad51a7402bf1943 /usr.bin/rcs/ci.c | |
parent | 0e03d3dfb6a2be983878e46762b62fe6226a2a85 (diff) |
Relieve checkin_update and checkin_init of the responsibility of
calling rcs_close() so we don't try to rcs_close() the same file
twice if the working file does not exist, resulting in a core dump.
The current code also returns the status of the last file, so if
we do:
$ touch file
$ ci nonexistent file
that will return 0. GNU returns 1. Fix that.
Additionally, it returns -1 on error, which turns into 255. It
should return 1.
OK niallo@
Diffstat (limited to 'usr.bin/rcs/ci.c')
-rw-r--r-- | usr.bin/rcs/ci.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c index 67c7db491ed..a3bd40f0fdd 100644 --- a/usr.bin/rcs/ci.c +++ b/usr.bin/rcs/ci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ci.c,v 1.148 2006/04/16 12:30:00 niallo Exp $ */ +/* $OpenBSD: ci.c,v 1.149 2006/04/17 12:03:19 ray Exp $ */ /* * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -289,10 +289,13 @@ checkin_main(int argc, char **argv) pb.file->rf_flags |= RCS_CREATE; } - if (pb.flags & NEWFILE) - status = checkin_init(&pb); - else - status = checkin_update(&pb); + if (pb.flags & NEWFILE) { + if (checkin_init(&pb) == -1) + status = 1; + } else { + if (checkin_update(&pb) == -1) + status = 1; + } /* reset NEWFILE flag */ pb.flags &= ~NEWFILE; @@ -465,10 +468,12 @@ checkin_getinput(const char *prompt) static int checkin_update(struct checkin_params *pb) { - char *filec, numb1[64], numb2[64]; + char *filec, numb1[64], numb2[64]; struct stat st; BUF *bp; + filec = NULL; + /* * XXX this is wrong, we need to get the revision the user * has the lock for. So we can decide if we want to create a @@ -477,10 +482,8 @@ checkin_update(struct checkin_params *pb) pb->frev = pb->file->rf_head; /* Load file contents */ - if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) { - rcs_close(pb->file); - return (-1); - } + if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) + goto fail; cvs_buf_putc(bp, '\0'); filec = (char *)cvs_buf_release(bp); @@ -624,7 +627,8 @@ checkin_update(struct checkin_params *pb) return (0); fail: - xfree(filec); + if (filec != NULL) + xfree(filec); if (pb->deltatext != NULL) xfree(pb->deltatext); return (-1); @@ -645,6 +649,8 @@ checkin_init(struct checkin_params *pb) const char *rcs_desc; struct stat st; + filec = NULL; + /* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */ if (pb->newrev != NULL && RCSNUM_ZERO_ENDING(pb->newrev)) { pb->frev = rcsnum_alloc(); @@ -654,10 +660,8 @@ checkin_init(struct checkin_params *pb) } /* Load file contents */ - if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) { - rcs_close(pb->file); - return (-1); - } + if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) + goto fail; cvs_buf_putc(bp, '\0'); filec = (char *)cvs_buf_release(bp); @@ -772,7 +776,8 @@ skipdesc: return (0); fail: - xfree(filec); + if (filec != NULL) + xfree(filec); return (-1); } |