Skip to content

Commit c5e3bc6

Browse files
phillipwoodgitster
authored andcommitted
config: avoid "write_in_full(fd, buf, len) != len" pattern
As explained in commit 06f46f2 (avoid "write_in_full(fd, buf, len) != len" pattern, 2017–09–13) the return value of write_in_full() is either -1 or the requested number of bytes. As such comparing the return value to an unsigned value such as strbuf.len will fail to catch errors. Change the code to use the preferred '< 0' check. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5435ff commit c5e3bc6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
27002700
* multiple [branch "$name"] sections.
27012701
*/
27022702
if (copystr.len > 0) {
2703-
if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
2703+
if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
27042704
ret = write_error(get_lock_file_path(lock));
27052705
goto out;
27062706
}
@@ -2763,7 +2763,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
27632763
* logic in the loop above.
27642764
*/
27652765
if (copystr.len > 0) {
2766-
if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
2766+
if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
27672767
ret = write_error(get_lock_file_path(lock));
27682768
goto out;
27692769
}

0 commit comments

Comments
 (0)