config-set: check write-in-full returns in set_multivar

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2007-01-11 13:16:26 -08:00
parent d1b2ddc863
commit 93c1e07947

View File

@ -694,10 +694,8 @@ int git_config_set_multivar(const char* key, const char* value,
store.key = (char*)key; store.key = (char*)key;
if (!store_write_section(fd, key) || if (!store_write_section(fd, key) ||
!store_write_pair(fd, key, value)) { !store_write_pair(fd, key, value))
ret = write_error(); goto write_err_out;
goto out_free;
}
} else { } else {
struct stat st; struct stat st;
char* contents; char* contents;
@ -777,31 +775,33 @@ int git_config_set_multivar(const char* key, const char* value,
/* write the first part of the config */ /* write the first part of the config */
if (copy_end > copy_begin) { if (copy_end > copy_begin) {
write_in_full(fd, contents + copy_begin, if (write_in_full(fd, contents + copy_begin,
copy_end - copy_begin); copy_end - copy_begin) <
if (new_line) copy_end - copy_begin)
write_in_full(fd, "\n", 1); goto write_err_out;
if (new_line &&
write_in_full(fd, "\n", 1) != 1)
goto write_err_out;
} }
copy_begin = store.offset[i]; copy_begin = store.offset[i];
} }
/* write the pair (value == NULL means unset) */ /* write the pair (value == NULL means unset) */
if (value != NULL) { if (value != NULL) {
if (store.state == START) if (store.state == START) {
if (!store_write_section(fd, key)) { if (!store_write_section(fd, key))
ret = write_error(); goto write_err_out;
goto out_free;
}
if (!store_write_pair(fd, key, value)) {
ret = write_error();
goto out_free;
} }
if (!store_write_pair(fd, key, value))
goto write_err_out;
} }
/* write the rest of the config */ /* write the rest of the config */
if (copy_begin < st.st_size) if (copy_begin < st.st_size)
write_in_full(fd, contents + copy_begin, if (write_in_full(fd, contents + copy_begin,
st.st_size - copy_begin); st.st_size - copy_begin) <
st.st_size - copy_begin)
goto write_err_out;
munmap(contents, st.st_size); munmap(contents, st.st_size);
unlink(config_filename); unlink(config_filename);
@ -824,6 +824,11 @@ out_free:
free(lock_file); free(lock_file);
} }
return ret; return ret;
write_err_out:
ret = write_error();
goto out_free;
} }
int git_config_rename_section(const char *old_name, const char *new_name) int git_config_rename_section(const char *old_name, const char *new_name)