[glib/wip/3v1n0/regex-pcre2-flags-fixes: 7/11] regex: Use size types more in line with PCRE2 returned values




commit 05c5bb1ca65c26de81d18363e64703c0dcd59cff
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Sep 6 18:21:52 2022 +0200

    regex: Use size types more in line with PCRE2 returned values
    
    We're using int for every size value while PCRE uses uint_32t or
    PCRE2_SIZE (size_t in most platforms), let's use the same types to avoid
    using different signs.

 glib/gregex.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/glib/gregex.c b/glib/gregex.c
index 367379d109..39fc570142 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#include <stdint.h>
 #include <string.h>
 
 #define PCRE2_CODE_UNIT_WIDTH 8
@@ -238,10 +239,10 @@ struct _GMatchInfo
   gint matches;                 /* number of matching sub patterns, guaranteed to be <= (n_subpatterns + 1) 
if doing a single match (rather than matching all) */
   gint n_subpatterns;           /* total number of sub patterns in the regex */
   gint pos;                     /* position in the string where last match left off */
-  gint  n_offsets;              /* number of offsets */
+  uint32_t n_offsets;           /* number of offsets */
   gint *offsets;                /* array of offsets paired 0,1 ; 2,3 ; 3,4 etc */
   gint *workspace;              /* workspace for pcre2_dfa_match() */
-  gint n_workspace;             /* number of workspace elements */
+  PCRE2_SIZE n_workspace;       /* number of workspace elements */
   const gchar *string;          /* string passed to the match function */
   gssize string_len;            /* length of string, in bytes */
   pcre2_match_context *match_context;
@@ -841,9 +842,9 @@ recalc_match_offsets (GMatchInfo *match_info,
                       GError     **error)
 {
   PCRE2_SIZE *ovector;
-  gint i;
+  uint32_t i;
 
-  if (pcre2_get_ovector_count (match_info->match_data) > G_MAXINT / 2)
+  if (pcre2_get_ovector_count (match_info->match_data) > G_MAXUINT32 / 2)
     {
       g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH,
                    _("Error while matching regular expression %s: %s"),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]