Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120411

RegEx parsing of long strings fails every 768 bytes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.6.1
    • Core: Other
    • None
    • Qt Creator v12.0.1
      build-src-Desktop_Qt_6_6_1_MinGW_64_bit-Debug
    • Windows

      The following code (cut down decoding GPS coords from an XML file) decodes the source X coordinate data incorrectly with a regual pattern. All the source coords start with -2.2xxxx but the decoding incorrectly returns a whole number for the X value with a regual pattern (every 0x0300 source bytes).

      Output from the program:

        1    -2.272871656290927    53.365228490332328    0.000000000000000
        2    -2.266970796656568    53.365971118655018    0.000000000000000
        3    -2.264664096981319    53.366368035381363    0.000000000000000
        4    -2.264181299374872    53.366368035381363    0.000000000000000
        5    -2.262303753127576    53.366163175597222    0.000000000000000
        6    -2.256424351164628    53.365394942633600    0.000000000000000
        7    -2.254621906767204    53.365260500440790    0.000000000000000
        8    -2.253259344633471    53.365234892355943    0.000000000000000
        9    -2.253034039083790    53.365337324602898    0.000000000000000
       10    -2.252873106548307    53.365516580442552    0.000000000000000
       11    -2.252819462369813    53.365747051128153    0.000000000000000
       12    -2.252798004698402    53.367187464667190    0.000000000000000
       13    -2.252529783805932    53.368230933833971    0.000000000000000
       14    -2.252272291749166    53.368915896630803    0.000000000000000
       15    -2.251768036471339    53.369805691668120    0.000000000000000
       16    -2.251435442564670    53.370330598009993    0.000000000000000
       17    -2.250362558994786    53.371604429188473    0.000000000000000
       18    -2.249085827546631    53.372775808157677    0.000000000000000
       19    -2.248989268025317    53.372955032699487    0.000000000000000
       20    -2.249075098710926    53.373063847231897    0.000000000000000
       21    -2.249075098710926    53.373063847231897    0.000000000000000
       22    6.000000000000000    53.373063847231897    0.000000000000000
       23    -2.249075098710926    53.373063847231897    0.000000000000000
       24    -2.249321861931987    53.373185463145091    0.000000000000000
       25    -2.252014799692400    53.374580820878933    0.000000000000000
       26    -2.253270073469177    53.375201676367944    0.000000000000000
       27    -2.254471703067427    53.375649710789382    0.000000000000000
       28    -2.255426569444617    53.375880126656533    0.000000000000000
       29    -2.257293386856239    53.376187345873618    0.000000000000000
       30    -2.258205337890640    53.376328153940797    0.000000000000000
       31    -2.260490579894479    53.376904182095082    0.000000000000000
       32    -2.261359615586091    53.377147391643213    0.000000000000000
       33    -2.263988180332305    53.378152216368257    0.000000000000000
       34    -2.264513893281510    53.378401818833957    0.000000000000000
       35    -2.264626546056367    53.378475419281692    0.000000000000000
       36    -2.264621181638498    53.378654619839992    0.000000000000000
       37    -2.264256401224745    53.378965019022679    0.000000000000000
       38    -2.263516111561532    53.380820966926180    0.000000000000000
       39    -2.263322992518965    53.380929761362353    0.000000000000000
       40    -2.260039968795115    53.381928097327119    0.000000000000000
       41    -2.259342594474691    53.382043288432243    0.000000000000000
       42    -2.258398456933175    53.382113682843048    0.000000000000000
       43    -2.257701082612751    53.382100883867913    0.000000000000000
       44    1.000000000000000    53.382100883867913    0.000000000000000
       45    -2.257153911992135    53.382056087424672    0.000000000000000
       46    -2.256799860414055    53.382107283355978    0.000000000000000
       47    -2.256477995343090    53.382196876087633    0.000000000000000
       48    -2.256359978150397    53.382292868090907    0.000000000000000
       49    -2.256284876300524    53.382465653151492    0.000000000000000

       

      The program:

      void main ()
      {    
          static const char            *SOURCE_DATA =
      "-2.272871656290927,53.36522849033233,0 "
      "-2.266970796656568,53.36597111865502,0 "
      "-2.264664096981319,53.36636803538136,0 "
      "-2.264181299374872,53.36636803538136,0 "
      "-2.262303753127576,53.36616317559722,0 "
      "-2.256424351164628,53.3653949426336,0 "
      "-2.254621906767204,53.36526050044079,0 "
      "-2.253259344633471,53.36523489235594,0 "
      "-2.25303403908379,53.3653373246029,0 "
      "-2.252873106548307,53.36551658044255,0 "
      "-2.252819462369813,53.36574705112815,0 "
      "-2.252798004698402,53.36718746466719,0 "
      "-2.252529783805932,53.36823093383397,0 "
      "-2.252272291749166,53.3689158966308,0 "
      "-2.251768036471339,53.36980569166812,0 "
      "-2.25143544256467,53.37033059800999,0 "
      "-2.250362558994786,53.37160442918847,0 "
      "-2.249085827546631,53.37277580815768,0 "
      "-2.248989268025317,53.37295503269949,0 "
      "-2.249075098710926,53.3730638472319,0 "        // parsed ok
      "-2.249075098710926,53.3730638472319,0 "        // error here
      "-2.249075098710926,53.3730638472319,0 "        // parsed ok
      "-2.249321861931987,53.37318546314509,0 "
      "-2.2520147996924,53.37458082087893,0 "
      "-2.253270073469177,53.37520167636794,0 "
      "-2.254471703067427,53.37564971078938,0 "
      "-2.255426569444617,53.37588012665653,0 "
      "-2.257293386856239,53.37618734587362,0 "
      "-2.25820533789064,53.3763281539408,0 "
      "-2.260490579894479,53.37690418209508,0 "
      "-2.261359615586091,53.37714739164321,0 "
      "-2.263988180332305,53.37815221636826,0 "
      "-2.26451389328151,53.37840181883396,0 "
      "-2.264626546056367,53.37847541928169,0 "
      "-2.264621181638498,53.37865461983999,0 "
      "-2.264256401224745,53.37896501902268,0 "
      "-2.263516111561532,53.38082096692618,0 "
      "-2.263322992518965,53.38092976136235,0 "
      "-2.260039968795115,53.38192809732712,0 "
      "-2.259342594474691,53.38204328843224,0 "
      "-2.258398456933175,53.38211368284305,0 "
      "-2.257701082612751,53.38210088386791,0 "
      "-2.257153911992135,53.38205608742467,0 "        // error repeats here
      "-2.256799860414055,53.38210728335598,0 "
      "-2.25647799534309,53.38219687608763,0 "
      "-2.256359978150397,53.38229286809091,0 "
      "-2.256284876300524,53.38246565315149,0 ";    
          static QRegularExpression    regex ("([+-]?[0-9]+[.]?[0-9]*)" ","    "([+-]?[0-9]+[.]?[0-9]*)" ","    "([+-]?[0-9]+[.]?[0-9]*)");
          QString                        coord_str = SOURCE_DATA;
          QRegularExpressionMatch        match;
          int                            str_index;
      
          str_index = 0;
          while ((match=regex.match (coord_str, str_index)).hasMatch ())
          {
              struct \{ double mX, mY, mZ; } pt;
              bool                        x_ok, y_ok, z_ok;
              pt.mX = match.captured (1).toDouble (&x_ok);
              pt.mY = match.captured (2).toDouble (&y_ok);
              pt.mZ = match.captured (3).toDouble (&z_ok);
              if ((!x_ok) || (!y_ok) || (!z_ok))
              {
                  printf ("bugger  x:%d:%s  y:%d:%s  z:%d:%s\n"
                          , x_ok, match.captured (1).toUtf8().constData ()
                          , y_ok, match.captured (2).toUtf8().constData ()
                          , z_ok, match.captured (3).toUtf8().constData ()
                          );
              }
              static int count=1;
              printf ("%3d\t%.15f\t%.15f\t%.15f\n", count, pt.mX, pt.mY, pt.mZ);
              fflush (stdout);
              count++;
      
              // do something with captured data
      
              str_index += match.capturedLength (0);
          }
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            thiago Thiago Macieira
            chrisemsen Chris Emsen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes