[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] Low-hanging portability fixes.
commit e6cf978c7cc2251564e8547e201b3f74a715a87e
Author: Zack Weinberg <zackw@xxxxxxxxx>
Date: Thu Jul 7 16:40:21 2011 -0700
Low-hanging portability fixes.
* Modernize Makefile.am and configure.ac.
* Remove a whole bunch of checks from configure.ac that probably were
unnecessary and the code wasn't bothering to pay attention to, anyway.
* Make the configure script agree with the code on the way to detect Windows.
* Remove an unnecessary Windows #ifdef block.
* Define SIZE_T_CEILING in a way that doesn't need a configure check.
* GCC uninitialized-variable warning fix in the test suite.
---
Makefile.am | 8 +++-----
configure.ac | 42 +++++++++++++++++++-----------------------
src/test/unittest_socks.c | 1 +
src/util.c | 8 ++++----
src/util.h | 15 ---------------
5 files changed, 27 insertions(+), 47 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 614748f..eb32bdc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
-AUTOMAKE_OPTIONS = foreign
-ACLOCAL_AMFLAGS = -I m4
-CFLAGS = -DDEBUG -g -Wall -O2 -Werror @libevent_CFLAGS@ @openssl_CFLAGS@
+ACLOCAL_AMFLAGS = -I m4
+AM_CFLAGS = -DDEBUG -Wall -Werror @libevent_CFLAGS@ @openssl_CFLAGS@
+LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @ws32_LIBS@
bin_PROGRAMS = obfsproxy
noinst_LIBRARIES = libobfsproxy.a
@@ -18,7 +18,6 @@ libobfsproxy_a_SOURCES = \
obfsproxy_SOURCES = \
src/main.c
-obfsproxy_LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @LIB_WS32@
unittests_SOURCES = \
src/test/tinytest.c \
@@ -26,7 +25,6 @@ unittests_SOURCES = \
src/test/unittest_obfs2.c \
src/test/unittest_crypt.c \
src/test/unittest_socks.c
-unittests_LDADD = libobfsproxy.a @libevent_LIBS@ @openssl_LIBS@ @LIB_WS32@
noinst_HEADERS = \
src/network.h \
diff --git a/configure.ac b/configure.ac
index c799d61..e49ddf3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,34 +1,30 @@
-AC_INIT
-AM_INIT_AUTOMAKE(obsproxy, 0.0)
-AM_CONFIG_HEADER(config.h)
+AC_PREREQ([2.67])dnl Possibly earlier will do, but this is what I have
+AC_INIT([obsproxy], [0.0])
+AC_CONFIG_SRCDIR([src/main.c])
-AC_CANONICAL_HOST
+AM_INIT_AUTOMAKE([foreign])
-AC_PROG_GCC_TRADITIONAL
-AC_PROG_SED
+AC_PROG_CC
+AC_PROG_CPP
AC_PROG_RANLIB
PKG_PROG_PKG_CONFIG
-AC_CHECK_HEADERS(stdint.h unistd.h fcntl.h)
-
PKG_CHECK_MODULES([libevent], [libevent >= 2.0])
PKG_CHECK_MODULES([openssl], [openssl >= 0.9.7])
-# We don't need -lssl, only -lcrypto
-openssl_LIBS=`echo "$openssl_LIBS" | $SED -e 's/-lssl//'`
-
-AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes)
-AM_CONDITIONAL(HAVE_WINSOCK2_H, test "x$HAVE_WINSOCK2_H" = "xyes")
-if test "x$HAVE_WINSOCK2_H" = "xyes"; then
- LIB_WS32=-lws2_32
-else
- LIB_WS32=
-fi
-AC_SUBST(LIB_WS32)
-
-AC_CHECK_SIZEOF(size_t)
+AC_CACHE_CHECK([for winsock], [ac_cv_lib_winsock],
+ [AC_PREPROC_IFELSE(
+ [#ifndef _WIN32
+ #error "not windows"
+ #endif
+ ],
+ [ac_cv_lib_winsock=yes], [ac_cv_lib_winsock=no])
+])
+AS_IF([test "x$ac_cv_lib_winsock" = xyes],
+ [ws32_LIBS=-lws2_32],
+ [ws32_LIBS=])
+AC_SUBST(ws32_LIBS)
AC_CONFIG_FILES([Makefile])
-
+AC_CONFIG_HEADERS([config.h])
AC_OUTPUT
-
diff --git a/src/test/unittest_socks.c b/src/test/unittest_socks.c
index c85fcf9..c77e3dc 100644
--- a/src/test/unittest_socks.c
+++ b/src/test/unittest_socks.c
@@ -425,6 +425,7 @@ test_socks_socks4_request(void *data)
/* First test:
Correct SOCKS4 req packet with nothing in the optional field. */
struct parsereq pr1;
+ memset(&pr1, 0, sizeof(struct parsereq));
state->parsereq = pr1;
uchar req1[8];
req1[0] = 1;
diff --git a/src/util.c b/src/util.c
index 7e3e747..70a6586 100644
--- a/src/util.c
+++ b/src/util.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <assert.h>
+#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -21,6 +22,9 @@
#include <event2/util.h>
#include <event2/dns.h>
+/** Any size_t larger than this amount is likely to be an underflow. */
+#define SIZE_T_CEILING (SIZE_MAX/2 - 16)
+
static const char *sev_to_string(int severity);
static int sev_is_valid(int severity);
static int write_logfile_prologue(int fd);
@@ -137,11 +141,7 @@ obfs_vsnprintf(char *str, size_t size, const char *format, va_list args)
return -1; /* no place for the NUL */
if (size > SIZE_T_CEILING)
return -1;
-#ifdef MS_WINDOWS
- r = _vsnprintf(str, size, format, args);
-#else
r = vsnprintf(str, size, format, args);
-#endif
str[size-1] = '\0';
if (r < 0 || r >= (ssize_t)size)
return -1;
diff --git a/src/util.h b/src/util.h
index 2705d51..ee04c85 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,8 +8,6 @@
/* va_list definition */
#include <stdarg.h>
-#include "config.h"
-
struct sockaddr_storage;
struct event_base;
struct evdns_base;
@@ -27,19 +25,6 @@ int init_evdns_base(struct event_base *base);
/***** String functions stuff. *****/
-/* The sizeof a size_t, as computed by sizeof. */
-#ifndef SSIZE_T_MAX
-#if (SIZEOF_SIZE_T == 4)
-#define SSIZE_T_MAX INT32_MAX
-#elif (SIZEOF_SIZE_T == 8)
-#define SSIZE_T_MAX INT64_MAX
-#else
-#error "Can't define SSIZE_T_MAX"
-#endif
-#endif
-/** Any size_t larger than this amount is likely to be an underflow. */
-#define SIZE_T_CEILING ((size_t)(SSIZE_T_MAX-16))
-
#ifndef __GNUC__
#define __attribute__(x)
#endif
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits