From a0f9006e5a8c844a9d36d85307d3ad5d5b24ed78 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 8 Feb 2017 17:25:01 -0800 Subject: [PATCH 1/4] #undef _POSIX_C_SOURCE if already defined --- programs/platform.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/programs/platform.h b/programs/platform.h index f30528aa..b54b94d7 100644 --- a/programs/platform.h +++ b/programs/platform.h @@ -1,6 +1,6 @@ /** * platform.h - compiler and OS detection - * + * * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc. * All rights reserved. * @@ -23,7 +23,7 @@ extern "C" { ****************************************/ #if defined(_MSC_VER) # define _CRT_SECURE_NO_WARNINGS /* Disable Visual Studio warning messages for fopen, strncpy, strerror */ -# define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before and */ +# define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before and */ # if (_MSC_VER <= 1800) /* (1800 = Visual Studio 2013) */ # define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */ # endif @@ -52,7 +52,7 @@ extern "C" { * Turn on Large Files support (>4GB) for 32-bit Linux/Unix ***********************************************************/ #if !defined(__64BIT__) /* No point defining Large file for 64 bit */ -# if !defined(_FILE_OFFSET_BITS) +# if !defined(_FILE_OFFSET_BITS) # define _FILE_OFFSET_BITS 64 /* turn off_t into a 64-bit type for ftello, fseeko */ # endif # if !defined(_LARGEFILE_SOURCE) /* obsolete macro, replaced with _FILE_OFFSET_BITS */ @@ -77,6 +77,9 @@ extern "C" { # define PLATFORM_POSIX_VERSION 200112L # else # if defined(__linux__) || defined(__linux) +# ifdef _POSIX_C_SOURCE +# undef _POSIX_C_SOURCE +# endif # define _POSIX_C_SOURCE 200112L /* use feature test macro */ # endif # include /* declares _POSIX_VERSION */ From e0b3265e87e30b57d5bf8c6c5acbab20c44d9f67 Mon Sep 17 00:00:00 2001 From: Sean Purcell Date: Wed, 8 Feb 2017 15:31:47 -0800 Subject: [PATCH 2/4] Fix ZSTD_getErrorString and add tests --- lib/common/zstd_common.c | 2 +- tests/fuzzer.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/common/zstd_common.c b/lib/common/zstd_common.c index 749b2870..8408a589 100644 --- a/lib/common/zstd_common.c +++ b/lib/common/zstd_common.c @@ -41,7 +41,7 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); } /*! ZSTD_getErrorString() : * provides error code string from enum */ -const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); } +const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); } /*=************************************************************** diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 60546c07..84d2c023 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -505,6 +505,16 @@ static int basicUnitTests(U32 seed, double compressibility) if (r != _3BYTESTESTLENGTH) goto _output_error; } DISPLAYLEVEL(4, "OK \n"); + /* error string tests */ + DISPLAYLEVEL(4, "test%3i : testing ZSTD error code strings : ", testNb++); + if (strcmp("No error detected", ZSTD_getErrorName((ZSTD_ErrorCode)(0-ZSTD_error_no_error))) != 0) goto _output_error; + if (strcmp("No error detected", ZSTD_getErrorString(ZSTD_error_no_error)) != 0) goto _output_error; + if (strcmp("Unspecified error code", ZSTD_getErrorString((ZSTD_ErrorCode)(0-ZSTD_error_GENERIC))) != 0) goto _output_error; + if (strcmp("Error (generic)", ZSTD_getErrorName((size_t)0-ZSTD_error_GENERIC)) != 0) goto _output_error; + if (strcmp("Error (generic)", ZSTD_getErrorString(ZSTD_error_GENERIC)) != 0) goto _output_error; + if (strcmp("No error detected", ZSTD_getErrorName(ZSTD_error_GENERIC)) != 0) goto _output_error; + DISPLAYLEVEL(4, "OK \n"); + _end: free(CNBuffer); free(compressedBuffer); From 545987996a198c090fd7d1e591157505a5b02b41 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 8 Feb 2017 17:38:17 -0800 Subject: [PATCH 3/4] Fix deprecation warnings for clang with C++14 --- lib/deprecated/zbuff.h | 4 +++- lib/dictBuilder/zdict.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index 85f97355..f6209197 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -42,7 +42,9 @@ extern "C" { #ifdef ZBUFF_DISABLE_DEPRECATE_WARNINGS # define ZBUFF_DEPRECATED(message) ZSTDLIB_API /* disable deprecation warnings */ #else -# if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__) +# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ +# define ZBUFF_DEPRECATED(message) [[deprecated(message)]] ZSTDLIB_API +# elif (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__) # define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated(message))) # elif defined(__GNUC__) && (__GNUC__ >= 3) # define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated)) diff --git a/lib/dictBuilder/zdict.h b/lib/dictBuilder/zdict.h index 4d0a62a2..4ead4474 100644 --- a/lib/dictBuilder/zdict.h +++ b/lib/dictBuilder/zdict.h @@ -174,7 +174,7 @@ ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBuffer #else # define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ -# define ZDICT_DEPRECATED(message) ZDICTLIB_API [[deprecated(message)]] +# define ZDICT_DEPRECATED(message) [[deprecated(message)]] ZDICTLIB_API # elif (ZDICT_GCC_VERSION >= 405) || defined(__clang__) # define ZDICT_DEPRECATED(message) ZDICTLIB_API __attribute__((deprecated(message))) # elif (ZDICT_GCC_VERSION >= 301) From d08019813be545a66de0afa8718261df44efd7dc Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 9 Feb 2017 14:20:52 -0800 Subject: [PATCH 4/4] Improvement from @inikep --- programs/platform.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/programs/platform.h b/programs/platform.h index b54b94d7..def8945b 100644 --- a/programs/platform.h +++ b/programs/platform.h @@ -77,10 +77,9 @@ extern "C" { # define PLATFORM_POSIX_VERSION 200112L # else # if defined(__linux__) || defined(__linux) -# ifdef _POSIX_C_SOURCE -# undef _POSIX_C_SOURCE +# ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L /* use feature test macro */ # endif -# define _POSIX_C_SOURCE 200112L /* use feature test macro */ # endif # include /* declares _POSIX_VERSION */ # if defined(_POSIX_VERSION) /* POSIX compliant */