config: avoid "write_in_full(fd, buf, len) != len" pattern
As explained in commit 06f46f237 (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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Nov 15, 2017 at 12:40 UTC
c5e3bc6ec46071397b40582157214d374d1b4fab
1 file changed
+2
-2
config.c
+2
-2
@@ -2700,7 +2700,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
2700
* multiple [branch "$name"] sections.
2701
*/
2702
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) {
2704
ret = write_error(get_lock_file_path(lock));
2705
goto out;
2706
}
@@ -2763,7 +2763,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
2763
* logic in the loop above.
2764
*/
2765
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) {
2767
ret = write_error(get_lock_file_path(lock));
2768
goto out;
2769
}