]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - src/coloredstderr.c
Handle invalid arguments to close()/fclose() better.
[coloredstderr/coloredstderr.git] / src / coloredstderr.c
index db6cb27e9f14771a70581222ece7704b816c8d7e..b7e71e17871d6f7c7411c4c922d48cfcb2530680 100644 (file)
@@ -396,14 +396,20 @@ static int (*real_close)(int);
 int close(int fd) {
     DLSYM_FUNCTION(real_close, "close");
 
-    close_fd(fd);
+    if (fd >= 0) {
+        close_fd(fd);
+    }
     return real_close(fd);
 }
 static int (*real_fclose)(FILE *);
 int fclose(FILE *fp) {
+    int fd;
+
     DLSYM_FUNCTION(real_fclose, "fclose");
 
-    close_fd(fileno(fp));
+    if (fp != NULL && (fd = fileno(fp)) >= 0) {
+        close_fd(fd);
+    }
     return real_fclose(fp);
 }