Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

2 valgrind warnings and their fixes



In zleread() (in Zle/zle_main.c), I just added a line that sets the
first byte of the newly malloced "line" buffer to '\0'.  Without this,
typing a space as the first character on the line generates a warning
about magicspace()'s call of strchr() accessing uninitialized memory
(if space is bound to magic-space, of course).

Another warning that occurs quite a bit is this one:

Warning: invalid file descriptor -1 in syscall close()

Sure, that's not very worrisome, but it is easy to get rid of with a
simple change to zclose() that ensures that close() will only get called
when fd >= 0:

--- Src/utils.c	5 Oct 2004 10:39:43 -0000	1.66
+++ Src/utils.c	17 Oct 2004 20:35:51 -0000
@@ -1117,8 +1117,9 @@ zclose(int fd)
 	    coprocin = -1;
 	if (fd == coprocout)
 	    coprocout = -1;
+	return close(fd);
     }
-    return close(fd);
+    return -1;
 }
 
 /* Get a file name relative to $TMPPREFIX which *

Any reason why we wouldn't want to make this change?  I don't see anyone
that is expecting errno to be set in such a case (nor anyone who even
checks the return value of zclose()).

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author