Move to C99 (#73) and fix ULL integer literals (#69)

This commit is contained in:
Sebastian Pipping 2017-07-05 22:49:51 +02:00
parent 21efd0f600
commit 5f51145401
9 changed files with 23 additions and 48 deletions

View file

@ -19,7 +19,11 @@ Release 2.??? ????????????????
quality entropy enabled, e.g. with CMake; commit
ff0207e6076e9828e536b8d9cd45c9c92069b895
Bug fixes:
#69 Fix improper use of unsigned long long integer literals
Other changes:
#73 Start requiring a C99 compiler
#49 Fix "==" Bashism in configure script
#50 Fix too eager getrandom detection for Debian GNU/kFreeBSD
#52 and macOS
@ -32,6 +36,7 @@ Release 2.??? ????????????????
#72 CMake: Resolve mistaken executable permissions
Special thanks to:
Alexander Bluhm
Ben Boeckel
Cătălin Răceanu
Kerin Millar

View file

@ -61,7 +61,7 @@ AC_SUBST(LIBREVISION)
AC_SUBST(LIBAGE)
dnl Checks for programs.
AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_CXX
AC_PROG_INSTALL
@ -174,37 +174,6 @@ else
fi
AC_SUBST(FILEMAP)
dnl Needed for the test support code; this was found at
dnl http://lists.gnu.org/archive/html/bug-autoconf/2002-07/msg00028.html
# AC_CPP_FUNC
# ------------------ #
# Checks to see if ANSI C99 CPP variable __func__ works.
# If not, perhaps __FUNCTION__ works instead.
# If not, we'll just define __func__ to "".
AC_DEFUN([AC_CPP_FUNC],
[AC_REQUIRE([AC_PROG_CC_STDC])dnl
AC_CACHE_CHECK([for an ANSI C99-conforming __func__], ac_cv_cpp_func,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[const char *foo = __func__;]])],
[ac_cv_cpp_func=yes],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[const char *foo = __FUNCTION__;]])],
[ac_cv_cpp_func=__FUNCTION__],
[ac_cv_cpp_func=no])])])
if test $ac_cv_cpp_func = __FUNCTION__; then
AC_DEFINE(__func__,__FUNCTION__,
[Define to __FUNCTION__ or "" if `__func__' does not conform to
ANSI C.])
elif test $ac_cv_cpp_func = no; then
AC_DEFINE(__func__,"",
[Define to __FUNCTION__ or "" if `__func__' does not conform to
ANSI C.])
fi
])# AC_CPP_FUNC
AC_CPP_FUNC
dnl Some basic configuration:
AC_DEFINE([XML_NS], 1,

View file

@ -95,7 +95,7 @@ _run() {
local BASE_FLAGS='-pipe -Wall -Wextra -pedantic -Wno-overlength-strings'
BASE_FLAGS+=' --coverage --no-inline'
local CFLAGS="-std=c89 ${BASE_FLAGS}"
local CFLAGS="-std=c99 ${BASE_FLAGS}"
local CXXFLAGS="-std=c++98 ${BASE_FLAGS}"
(

View file

@ -24,7 +24,6 @@ extern "C" {
struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;
/* Should this be defined using stdbool.h when C99 is available? */
typedef unsigned char XML_Bool;
#define XML_TRUE ((XML_Bool) 1)
#define XML_FALSE ((XML_Bool) 0)

View file

@ -12,6 +12,7 @@
* HISTORY:
*
* 2017-07-05 (Sebastian Pipping)
* - Use _SIP_ULL macro to not require a C++11 compiler if compiled as C++
* - Add const qualifiers at two places
* - Ensure <=80 characters line length (assuming tab width 4)
*
@ -22,7 +23,6 @@
* - Clarify license note in the header
* - Address C89 issues:
* - Stop using inline keyword (and let compiler decide)
* - Turn integer suffix ULL to UL
* - Replace _Bool by int
* - Turn macro siphash24 into a function
* - Address invalid conversion (void pointer) by explicit cast
@ -94,6 +94,14 @@
#endif
/*
* Workaround to not require a C++11 compiler for using ULL suffix
* if this code is included and compiled as C++; related GCC warning is:
* warning: use of C++11 long long integer constant [-Wlong-long]
*/
#define _SIP_ULL(high, low) (((uint64_t)high << 32) | low)
#define SIP_ROTL(x, b) (uint64_t)(((x) << (b)) | ( (x) >> (64 - (b))))
#define SIP_U32TO8_LE(p, v) \
@ -175,10 +183,10 @@ static void sip_round(struct siphash *H, const int rounds) {
static struct siphash *sip24_init(struct siphash *H,
const struct sipkey *key) {
H->v0 = 0x736f6d6570736575UL ^ key->k[0];
H->v1 = 0x646f72616e646f6dUL ^ key->k[1];
H->v2 = 0x6c7967656e657261UL ^ key->k[0];
H->v3 = 0x7465646279746573UL ^ key->k[1];
H->v0 = _SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0];
H->v1 = _SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1];
H->v2 = _SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0];
H->v3 = _SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1];
H->p = H->buf;
H->c = 0;

View file

@ -864,7 +864,7 @@ generate_hash_secret_salt(XML_Parser parser)
return ENTROPY_DEBUG("fallback(4)", entropy * 2147483647);
} else {
return ENTROPY_DEBUG("fallback(8)",
entropy * (unsigned long)2305843009213693951);
entropy * (unsigned long)2305843009213693951ULL);
}
#endif
}

View file

@ -76,7 +76,7 @@ main() {
;;
esac
local CFLAGS="-std=c89 ${BASE_FLAGS} ${CFLAGS:-}"
local CFLAGS="-std=c99 ${BASE_FLAGS} ${CFLAGS:-}"
local CXXFLAGS="-std=c++98 ${BASE_FLAGS} ${CXXFLAGS:-}"
(

View file

@ -26,12 +26,6 @@ extern "C" {
#define __func__ __FUNCTION__
#endif
/* ISO C90 does not support '__func__' predefined identifier */
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ < 199901)) || \
(defined(__GNUC__) && !defined(__STDC_VERSION__))
# define __func__ "(unknown)"
#endif
#define START_TEST(testname) static void testname(void) { \
_check_set_test_info(__func__, __FILE__, __LINE__); \
{

View file

@ -247,7 +247,7 @@ START_TEST(test_siphash_spec)
const char message[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09"
"\x0a\x0b\x0c\x0d\x0e";
const size_t len = sizeof(message) - 1;
const uint64_t expected = 0xa129ca6149be45e5U;
const uint64_t expected = _SIP_ULL(0xa129ca61U, 0x49be45e5U);
struct siphash state;
struct sipkey key;
(void)sip_tobin;