commit_lock_file(): use a strbuf to manage temporary space

Avoid relying on the filename length restrictions that are currently checked by lock_file(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Oct 1, 2014 at 12:28 UTC 3e88e8fc085bbfad142d51a07ef918b9b5ca1d72
1 file changed +7 -5
lockfile.c
+7 -5
@@ -319,7 +319,8 @@ int reopen_lock_file(struct lock_file *lk)
319
320 int commit_lock_file(struct lock_file *lk)
321 {
322 - char result_file[PATH_MAX];
322 + static struct strbuf result_file = STRBUF_INIT;
323 + int err;
324
325 if (!lk->active)
326 die("BUG: attempt to commit unlocked object");
@@ -327,11 +328,12 @@ int commit_lock_file(struct lock_file *lk)
328 if (close_lock_file(lk))
329 return -1;
330
330 - strcpy(result_file, lk->filename);
331 /* remove ".lock": */
332 - result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
333 -
334 - if (rename(lk->filename, result_file)) {
332 + strbuf_add(&result_file, lk->filename,
333 + strlen(lk->filename) - LOCK_SUFFIX_LEN);
334 + err = rename(lk->filename, result_file.buf);
335 + strbuf_reset(&result_file);
336 + if (err) {
337 int save_errno = errno;
338 rollback_lock_file(lk);
339 errno = save_errno;