summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2020-04-23 15:41:23 +0000
committerph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2020-04-23 15:41:23 +0000
commitb941dacb37e5b7e18cf1e99ec10f5117a135a05e (patch)
tree79fb2d2d6e2b1275347a07ffa4aa481d1777eca7
parent6b1bd6c3d8e3b4146d303a387c85363849768701 (diff)
downloadpcre2-b941dacb37e5b7e18cf1e99ec10f5117a135a05e.tar.gz
Avoid using [-1] as a suffix in pcre2test as it can provoke a compiler warning.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@1245 6239d852-aaf2-0410-a92c-79f79f948069
-rw-r--r--ChangeLog3
-rw-r--r--src/pcre2test.c39
2 files changed, 31 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index f3ae2d4..f9663b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -101,6 +101,9 @@ LIST(APPEND...) to allow a setting from the command line to be included.
24. CMake build now checks for secure_getenv() and strerror(). Patch by Carlo.
+25. Avoid using [-1] as a suffix in pcre2test because it can provoke a compiler
+warning.
+
Version 10.34 21-November-2019
------------------------------
diff --git a/src/pcre2test.c b/src/pcre2test.c
index ed75e06..c4b6059 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -2980,15 +2980,21 @@ return (int)(pp - p);
*************************************************/
/* Must handle UTF-8 strings in utf8 mode. Yields number of characters printed.
-For printing *MARK strings, a negative length is given. If handed a NULL file,
-just counts chars without printing (because pchar() does that). */
+For printing *MARK strings, a negative length is given, indicating that the
+length is in the previous code unit. We can't use strlen() because the string
+may contain binary zeros. Avoid using [-1] as a suffix because this can provoke
+a compiler warning. If handed a NULL file, this function just counts chars
+without printing (because pchar() does that). */
static int pchars8(PCRE2_SPTR8 p, int length, BOOL utf, FILE *f)
{
uint32_t c = 0;
int yield = 0;
-
-if (length < 0) length = p[-1];
+if (length < 0)
+ {
+ PCRE2_SPTR8 pp = p - 1;
+ length = *pp;
+ }
while (length-- > 0)
{
if (utf)
@@ -3017,13 +3023,19 @@ return yield;
*************************************************/
/* Must handle UTF-16 strings in utf mode. Yields number of characters printed.
-For printing *MARK strings, a negative length is given. If handed a NULL file,
-just counts chars without printing. */
+For printing *MARK strings, a negative length is given, indicating that the
+length is in the previous code unit. Avoid using [-1] as a suffix because this
+can provoke a compiler warning. If handed a NULL file, just counts chars
+without printing. */
static int pchars16(PCRE2_SPTR16 p, int length, BOOL utf, FILE *f)
{
int yield = 0;
-if (length < 0) length = p[-1];
+if (length < 0)
+ {
+ PCRE2_SPTR16 pp = p - 1;
+ length = *pp;
+ }
while (length-- > 0)
{
uint32_t c = *p++ & 0xffff;
@@ -3051,15 +3063,20 @@ return yield;
*************************************************/
/* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
-For printing *MARK strings, a negative length is given. If handed a NULL file,
-just counts chars without printing. */
+For printing *MARK strings, a negative length is given, indicating that the
+length is in the previous code unit. Avoid using [-1] as a suffix because this
+can provoke a compiler warning. If handed a NULL file, just counts chars
+without printing. */
static int pchars32(PCRE2_SPTR32 p, int length, BOOL utf, FILE *f)
{
int yield = 0;
(void)(utf); /* Avoid compiler warning */
-
-if (length < 0) length = p[-1];
+if (length < 0)
+ {
+ PCRE2_SPTR32 pp = p - 1;
+ length = *pp;
+ }
while (length-- > 0)
{
uint32_t c = *p++;