[Pcre-svn] [1245] code/trunk: Avoid using [-1] as a suffix i…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1245] code/trunk: Avoid using [-1] as a suffix in pcre2test as it can provoke a compiler warning.
Revision: 1245
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1245
Author:   ph10
Date:     2020-04-23 16:41:23 +0100 (Thu, 23 Apr 2020)
Log Message:
-----------
Avoid using [-1] as a suffix in pcre2test as it can provoke a compiler warning.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2test.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2020-04-15 16:34:36 UTC (rev 1244)
+++ code/trunk/ChangeLog    2020-04-23 15:41:23 UTC (rev 1245)
@@ -101,7 +101,10 @@


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
------------------------------


Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2020-04-15 16:34:36 UTC (rev 1244)
+++ code/trunk/src/pcre2test.c    2020-04-23 15:41:23 UTC (rev 1245)
@@ -2980,15 +2980,21 @@
 *************************************************/


/* 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 @@
*************************************************/

/* 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 @@
*************************************************/

/* 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++;