From f7187b38c7b42e4d2d2389b0239d005779ec55db Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Thu, 19 Apr 2018 16:52:57 +0000 Subject: [PATCH] Apply some of Daniel Richard G's Windows patches. --- ChangeLog | 9 +++++++++ NON-AUTOTOOLS-BUILD | 19 ++++++++++++++++--- RunTest.bat | 2 +- src/pcre2grep.c | 18 ++++++++++++++---- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 398d2bb..c7c8543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,15 @@ architectures, alignment requirements take care of this automatically. 9. When returning an error from pcre2_pattern_convert(), ensure the error offset is set zero for early errors. +10. A number of patches for Windows support from Daniel Richard G: + + (a) List of error numbers in Runtest.bat corrected (it was not the same as in + Runtest). + + (b) pcre2grep snprintf() workaround as used elsewhere in the tree. + + (c) Support for non-C99 snprintf() that returns -1 in the overflow case. + Version 10.31 12-February-2018 ------------------------------ diff --git a/NON-AUTOTOOLS-BUILD b/NON-AUTOTOOLS-BUILD index 0775794..0bf4507 100644 --- a/NON-AUTOTOOLS-BUILD +++ b/NON-AUTOTOOLS-BUILD @@ -10,6 +10,7 @@ This document contains the following sections: Calling conventions in Windows environments Comments about Win32 builds Building PCRE2 on Windows with CMake + Building PCRE2 on Windows with Visual Studio Testing with RunTest.bat Building PCRE2 on native z/OS and z/VM @@ -328,6 +329,18 @@ cache can be deleted by selecting "File > Delete Cache". most recent build configuration is targeted by the tests. A summary of test results is presented. Complete test output is subsequently available for review in Testing\Temporary under your build dir. + + +BUILDING PCRE2 ON WINDOWS WITH VISUAL STUDIO + +The code currently cannot be compiled without a stdint.h header, which is +available only in relatively recent versions of Visual Studio. However, this +portable and permissively-licensed implementation of the header worked without +issue: + + http://www.azillionmonkeys.com/qed/pstdint.h + +Just rename it and drop it into the top level of the build tree. TESTING WITH RUNTEST.BAT @@ -382,6 +395,6 @@ Everything in that location, source and executable, is in EBCDIC and native z/OS file formats. The port provides an API for LE languages such as COBOL and for the z/OS and z/VM versions of the Rexx languages. -=============================== -Last Updated: 13 September 2017 -=============================== +=========================== +Last Updated: 19 April 2018 +=========================== diff --git a/RunTest.bat b/RunTest.bat index 0cd8bcc..6ff1c15 100644 --- a/RunTest.bat +++ b/RunTest.bat @@ -263,7 +263,7 @@ if errorlevel 1 ( set failed="yes" goto :eof ) else if [%1]==[2] ( - %pcre2test% %mode% %4 %5 %6 %7 %8 %9 -error -63,-62,-2,-1,0,100,188,189,190,191 >>%2%bits%\%testoutput% + %pcre2test% %mode% %4 %5 %6 %7 %8 %9 -error -65,-62,-2,-1,0,100,101,191,200 >>%2%bits%\%testoutput% ) set type= diff --git a/src/pcre2grep.c b/src/pcre2grep.c index a9379cf..c1bfdd6 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -96,6 +96,14 @@ POSSIBILITY OF SUCH DAMAGE. #define PCRE2_CODE_UNIT_WIDTH 8 #include "pcre2.h" +/* Older versions of MSVC lack snprintf(). This define allows for +warning/error-free compilation and testing with MSVC compilers back to at least +MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */ + +#if defined(_MSC_VER) && (_MSC_VER < 1900) +#define snprintf _snprintf +#endif + #define FALSE 0 #define TRUE 1 @@ -3663,16 +3671,18 @@ for (i = 1; i < argc; i++) { char buff1[24]; char buff2[24]; + int ret; int baselen = (int)(opbra - op->long_name); int fulllen = (int)(strchr(op->long_name, ')') - op->long_name + 1); int arglen = (argequals == NULL || equals == NULL)? (int)strlen(arg) : (int)(argequals - arg); - if (snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name) > - (int)sizeof(buff1) || - snprintf(buff2, sizeof(buff2), "%s%.*s", buff1, - fulllen - baselen - 2, opbra + 1) > (int)sizeof(buff2)) + if ((ret = snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name), + ret < 0 || ret > (int)sizeof(buff1)) || + (ret = snprintf(buff2, sizeof(buff2), "%s%.*s", buff1, + fulllen - baselen - 2, opbra + 1), + ret < 0 || ret > (int)sizeof(buff2))) { fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n", op->long_name);