Re: [PATCH v5 16/35] commit_lock_file(): inline temporary variable
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Sep 16, 2014, 22:16 UTC
- Message-ID
- <20140916221647.GP29050@google.com>
- In-Reply-To
- <1410896036-12750-17-git-send-email-mhagger@alum.mit.edu>
Michael Haggerty wrote:
Show 17 quoted lines
> --- a/lockfile.c
> +++ b/lockfile.c
> @@ -311,12 +311,14 @@ int reopen_lock_file(struct lock_file *lk)
> int commit_lock_file(struct lock_file *lk)
> {
> char result_file[PATH_MAX];
> - size_t i;
> +
> if (lk->fd >= 0 && close_lock_file(lk))
> return -1;
> +
> strcpy(result_file, lk->filename);
> - i = strlen(result_file) - LOCK_SUFFIX_LEN; /* .lock */
> - result_file[i] = 0;
> + /* remove ".lock": */
> + result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
> +Same comment as the delete_ref_loose patch: the reader can gain some piece of mind from an assertion at the top that makes sure filename is valid (which it always should be, according to the API):
assert(lk->filename[0]);
It would also be nice to use the same xmemdupz-based code as in the delete_ref_loose case (ideally via a helper), to avoid having to work with a PATH_MAX-sized buffer.
Otherwise looks good.
Thanks, Jonathan