1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

The size of long is a build time characteristic and as such it is now recorded

in curlbuild.h as CURL_SIZEOF_LONG. Definition now done from configure process
and in CVS curlbuild.h.dist for non-configure systems.
This commit is contained in:
Yang Tse 2008-08-13 15:32:20 +00:00
parent 64e3a091c3
commit feb03e4717
10 changed files with 127 additions and 34 deletions

13
CHANGES
View File

@ -6,6 +6,19 @@
Changelog
Yang Tse (13 Aug 2008)
- The size of long is a build time characteristic and as such it is now recorded
in curlbuild.h as CURL_SIZEOF_LONG. Definition now done from configure process
and in CVS curlbuild.h.dist for non-configure systems.
- Make SIZE_OF_LONG mandatory. It is not possible to build the library without
it. It will be defined by the configure process in generated config.h. And
can be defined in hand-crafted system-specific config.h files to the numeric
size that sizeof(long) would return for that specific platform. It might be
ABI dependant, if this is the case, the definition is equally ABI dependant,
its value normally will be 4 or 8. It can also be defined in curlbuild.h.dist
and maybe it is easier and more appropriate to make the definition here.
Daniel Fandrich (12 Aug 2008)
- Fixed a buffer overflow problem in Curl_proxyCONNECT that could occur
when a server responded with long headers and data. Luckily, the buffer

View File

@ -3613,6 +3613,43 @@ _EOF
])
dnl CURL_CONFIGURE_LONG
dnl -------------------------------------------------
dnl Find out the size of long as reported by sizeof() and define
dnl CURL_SIZEOF_LONG as appropriate to be used in template file
dnl include/curl/curlbuild.h.in to properly configure the library.
dnl The size of long is a build time characteristic and as such
dnl must be recorded in curlbuild.h
AC_DEFUN([CURL_CONFIGURE_LONG], [
if test ! -z "$ac_cv_sizeof_long"; then
AC_MSG_WARN([AC_CHECK_SIZEOF(long) was called before CURL_CONFIGURE_LONG])
fi
AC_MSG_CHECKING([size of long])
curl_sizeof_long="unknown"
for tmp_size in '16' '8' '4' '2' '1' ; do
if test "$curl_sizeof_long" = "unknown"; then
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
typedef char dummy_arr[sizeof(long) == $tmp_size ? 1 : -1];
]],[[
dummy_arr[1] = (long)1;
]])
],[
curl_sizeof_long="$tmp_size"
])
fi
done
if test "$curl_sizeof_long" = "unknown"; then
AC_MSG_ERROR([cannot find out size of long])
else
AC_MSG_RESULT([$curl_sizeof_long])
CURL_DEFINE_UNQUOTED([CURL_SIZEOF_LONG], [$curl_sizeof_long])
ac_cv_sizeof_long="$curl_sizeof_long"
fi
])
dnl CURL_INCLUDES_INTTYPES
dnl -------------------------------------------------
dnl Set up variable with list of headers that must be
@ -3722,13 +3759,9 @@ AC_DEFUN([CURL_CONFIGURE_CURL_OFF_T], [
AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
fi
#
AC_CHECK_SIZEOF(long)
CURL_CONFIGURE_LONG
AC_CHECK_SIZEOF(void*)
#
if test -z "$ac_cv_sizeof_long" ||
test "$ac_cv_sizeof_long" -eq "0"; then
AC_MSG_ERROR([cannot find out size of long.])
fi
if test -z "$ac_cv_sizeof_voidp" ||
test "$ac_cv_sizeof_voidp" -eq "0"; then
AC_MSG_ERROR([cannot find out size of void*.])

View File

@ -139,6 +139,7 @@
/* ================================================================ */
#if defined(__DJGPP__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -148,6 +149,7 @@
# define CURL_SUFFIX_CURL_OFF_TU UL
#elif defined(__SALFORDC__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -158,6 +160,7 @@
#elif defined(__BORLANDC__)
# if (__BORLANDC__ < 0x520)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -166,6 +169,7 @@
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
@ -176,6 +180,7 @@
# endif
#elif defined(__TURBOC__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -186,6 +191,7 @@
#elif defined(__WATCOMC__)
# if defined(__386__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
@ -194,6 +200,7 @@
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -205,6 +212,7 @@
#elif defined(__POCC__)
# if (__POCC__ < 280)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -213,6 +221,7 @@
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# elif defined(_MSC_VER)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
@ -221,6 +230,7 @@
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -231,6 +241,7 @@
# endif
#elif defined(__LCC__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -241,6 +252,7 @@
#elif defined(__SYMBIAN32__)
# if defined(__GCC32__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -250,6 +262,7 @@
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__CW32__)
# pragma longlong on
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -258,6 +271,7 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__VC32__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -268,6 +282,7 @@
# endif
#elif defined(__MWERKS__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -277,6 +292,7 @@
# define CURL_SUFFIX_CURL_OFF_TU ULL
#elif defined(_WIN32_WCE)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
@ -286,6 +302,7 @@
# define CURL_SUFFIX_CURL_OFF_TU ui64
#elif defined(__MINGW32__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
@ -294,27 +311,9 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
#elif defined(_MSC_VER)
# if (_MSC_VER >= 900)
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
# define CURL_FORMAT_OFF_T "%I64d"
# define CURL_SIZEOF_CURL_OFF_T 8
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
# define CURL_FORMAT_OFF_T "%ld"
# define CURL_SIZEOF_CURL_OFF_T 4
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
#elif defined(__VMS)
# if defined(__alpha) || defined(__ia64)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -323,6 +322,7 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -334,6 +334,7 @@
#elif defined(__OS400__)
# if defined(__ILEC400__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -346,6 +347,7 @@
#elif defined(__MVS__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_LONG_LONG)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -354,6 +356,7 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -362,6 +365,7 @@
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -375,6 +379,7 @@
#elif defined(__370__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_LONG_LONG)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -383,6 +388,7 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -391,6 +397,7 @@
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
@ -401,12 +408,38 @@
# endif
# endif
/* ===================================== */
/* KEEP MSVC THE PENULTIMATE ENTRY */
/* ===================================== */
#elif defined(_MSC_VER)
# if (_MSC_VER >= 900)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T __int64
# define CURL_FMT_OFF_T "I64d"
# define CURL_FMT_OFF_TU "I64u"
# define CURL_FORMAT_OFF_T "%I64d"
# define CURL_SIZEOF_CURL_OFF_T 8
# define CURL_SUFFIX_CURL_OFF_T i64
# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"
# define CURL_FORMAT_OFF_T "%ld"
# define CURL_SIZEOF_CURL_OFF_T 4
# define CURL_SUFFIX_CURL_OFF_T L
# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
/* ===================================== */
/* KEEP GENERIC GCC THE LAST ENTRY */
/* ===================================== */
#elif defined(__GNUC__)
# if defined(__i386__)
# define CURL_SIZEOF_LONG 4
# define CURL_OFF_T long long
# define CURL_FMT_OFF_T "lld"
# define CURL_FMT_OFF_TU "llu"
@ -415,6 +448,7 @@
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__x86_64__)
# define CURL_SIZEOF_LONG 8
# define CURL_OFF_T long
# define CURL_FMT_OFF_T "ld"
# define CURL_FMT_OFF_TU "lu"

View File

@ -108,6 +108,9 @@
# include <inttypes.h>
#endif
/* The expected size of long , as to be computed by sizeof. */
#undef CURL_SIZEOF_LONG
/* Signed integral data type used for curl_off_t. */
#undef CURL_OFF_T

View File

@ -76,6 +76,11 @@
* Verify that some macros are actually defined.
*/
#ifndef CURL_SIZEOF_LONG
# error "CURL_SIZEOF_LONG definition is missing!"
Error Compilation_aborted_CURL_SIZEOF_LONG_is_missing
#endif
#ifndef CURL_OFF_T
# error "CURL_OFF_T definition is missing!"
Error Compilation_aborted_CURL_OFF_T_is_missing
@ -119,6 +124,15 @@
#define CurlchkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
/*
* Verify that the size previously defined and expected for long
* is the same as the one reported by sizeof() at compile time.
*/
typedef char
__curl_rule_01__
[CurlchkszEQ(long, CURL_SIZEOF_LONG)];
/*
* Verify that the size previously defined and expected for
* curl_off_t is actually the the same as the one reported
@ -126,7 +140,7 @@
*/
typedef char
__curl_rule_01__
__curl_rule_02__
[CurlchkszEQ(curl_off_t, CURL_SIZEOF_CURL_OFF_T)];
/*
@ -136,7 +150,7 @@ typedef char
*/
typedef char
__curl_rule_02__
__curl_rule_03__
[CurlchkszGE(curl_off_t, long)];
/* ================================================================ */

View File

@ -595,6 +595,7 @@ $(CURL_INC)/curl/curlbuild.h: Makefile.netware FORCE
@echo $(DL)#ifndef __CURL_CURLBUILD_H$(DL) >> $@
@echo $(DL)#define __CURL_CURLBUILD_H$(DL) >> $@
ifeq ($(LIBARCH),LIBC)
@echo $(DL)#define CURL_SIZEOF_LONG 4$(DL) >> $@
@echo $(DL)#define CURL_OFF_T long long$(DL) >> $@
@echo $(DL)#define CURL_FMT_OFF_T "lld"$(DL) >> $@
@echo $(DL)#define CURL_FMT_OFF_TU "llu"$(DL) >> $@
@ -603,6 +604,7 @@ ifeq ($(LIBARCH),LIBC)
@echo $(DL)#define CURL_SUFFIX_CURL_OFF_T LL$(DL) >> $@
@echo $(DL)#define CURL_SUFFIX_CURL_OFF_TU ULL$(DL) >> $@
else
@echo $(DL)#define CURL_SIZEOF_LONG 4$(DL) >> $@
@echo $(DL)#define CURL_OFF_T long$(DL) >> $@
@echo $(DL)#define CURL_FMT_OFF_T "ld"$(DL) >> $@
@echo $(DL)#define CURL_FMT_OFF_TU "lu"$(DL) >> $@

View File

@ -712,9 +712,6 @@
/* Define to the type of arg 5 for `select'. */
#define SELECT_TYPE_ARG5 (struct timeval *)
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4
/* The size of `off_t', as computed by sizeof. */
#define SIZEOF_OFF_T 8

View File

@ -593,9 +593,6 @@
/* Define to the type of arg 5 for `select'. */
#define SELECT_TYPE_ARG5 (struct timeval *)
/* The size of a `long', as computed by sizeof. */
#define SIZEOF_LONG 8
/* The size of a `size_t', as computed by sizeof. */
#define SIZEOF_SIZE_T 8

View File

@ -41,7 +41,7 @@
* of 'long' the conversion funtion to use is strtol().
*/
#if (CURL_SIZEOF_CURL_OFF_T > SIZEOF_LONG)
#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
# ifdef HAVE_STRTOLL
# define curlx_strtoofft strtoll
# else

View File

@ -1387,7 +1387,7 @@ static int str2num(long *val, const char *str)
*/
static int str2offset(curl_off_t *val, const char *str)
{
#if (CURL_SIZEOF_CURL_OFF_T > SIZEOF_LONG)
#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
/* Ugly, but without going through a bunch of rigmarole, we don't have the
* definitions for LLONG_{MIN,MAX} or LONG_LONG_{MIN,MAX}.
*/