Add assert()s.

This commit is contained in:
Simon Ruderich
2013-06-13 21:33:27 +02:00
parent 37cb5686de
commit 6d6ad4423a
3 changed files with 33 additions and 1 deletions

View File

@@ -25,6 +25,12 @@
/* Must be loaded before the following headers. */
#include "ldpreload.h"
/* Disable assert()s if not compiled with --enable-debug. */
#ifndef DEBUG
# define NDEBUG
#endif
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
@@ -78,6 +84,8 @@ static int force_write_to_non_tty;
* additional call. */
static int isatty_noinline(int fd) noinline;
static int isatty_noinline(int fd) {
assert(fd >= 0);
int saved_errno = errno;
int result = isatty(fd);
errno = saved_errno;
@@ -91,6 +99,8 @@ static void dup_fd(int oldfd, int newfd) {
debug("%3d -> %3d\t\t\t[%d]\n", oldfd, newfd, getpid());
#endif
assert(oldfd >= 0 && newfd >= 0);
if (unlikely(!initialized)) {
init_from_environment();
}
@@ -113,6 +123,8 @@ static void close_fd(int fd) {
debug("%3d -> .\t\t\t[%d]\n", fd, getpid());
#endif
assert(fd >= 0);
if (unlikely(!initialized)) {
init_from_environment();
}