From 68d6dfb9996a5e143a981c6c902009fa68414e71 Mon Sep 17 00:00:00 2001
From: "Yury V. Zaytsev" <yury@shurup.com>
Date: Sat, 4 Aug 2012 18:55:07 +0200
Subject: [PATCH] Additional error handling in edit_save_block()
If edit->column_highlight is on and the disk is so full that the editor
is unable even to write the magic (r <= 0), then subsequent if (len)
check might fail, since the value of len is undefined.
The solution is to initialize len with a non-zero value, so that the
function properly returns an error value in all cases (adding an
explicit return 0; is also possible, but then one must take care of
closing file descriptors, which is less convenient).
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
---
src/editor/editcmd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
index 4ca6cee..ec20cbf 100644
a
|
b
|
edit_ok_to_exit (WEdit * edit) |
2908 | 2908 | int |
2909 | 2909 | edit_save_block (WEdit * edit, const char *filename, long start, long finish) |
2910 | 2910 | { |
2911 | | int len, file; |
| 2911 | int len = 1, file; |
2912 | 2912 | vfs_path_t *vpath; |
2913 | 2913 | |
2914 | 2914 | vpath = vfs_path_from_str (filename); |
2915 | 2915 | file = mc_open (vpath, O_CREAT | O_WRONLY | O_TRUNC, |
2916 | 2916 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY); |
2917 | 2917 | vfs_path_free (vpath); |
| 2918 | |
2918 | 2919 | if (file == -1) |
2919 | 2920 | return 0; |
2920 | 2921 | |
2921 | 2922 | if (edit->column_highlight) |
2922 | 2923 | { |
2923 | 2924 | int r; |
2924 | | |
2925 | 2925 | r = mc_write (file, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)); |
| 2926 | |
2926 | 2927 | if (r > 0) |
2927 | 2928 | { |
2928 | 2929 | unsigned char *block, *p; |
… |
… |
edit_save_block (WEdit * edit, const char *filename, long start, long finish) |
2957 | 2958 | g_free (buf); |
2958 | 2959 | } |
2959 | 2960 | mc_close (file); |
| 2961 | |
2960 | 2962 | if (len) |
2961 | 2963 | return 0; |
| 2964 | |
2962 | 2965 | return 1; |
2963 | 2966 | } |
2964 | 2967 | |