Changeset 518 for cpp


Ignore:
Timestamp:
06/22/16 16:36:43 (8 years ago)
Author:
Maciej Komosinski
Message:

More strict parsing of genotype format prefix

Location:
cpp/frams/genetics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geno.cpp

    r508 r518  
    3535                {
    3636                        int end;
    37                         SString newcomment;
    3837                        switch (genstring.charAt(1))
    3938                        {
    4039                        case '/':
    4140                                genformat = genstring.charAt(2);
     41                                if ((genformat=='\0')||(genformat=='\n'))
     42                                        genformat=INVALID_FORMAT;
    4243                                if ((end = genstring.indexOf('\n')) >= 0)
    4344                                {
    44                                         newcomment = genstring.substr(2, end - 2);
     45                                        if (end!=3) genformat=INVALID_FORMAT;
    4546                                        gencopy = genstring.substr(end + 1);
    4647                                        mapinshift = end + 1;
     
    4849                                else
    4950                                {
     51                                        if (genstring.len()!=3) genformat=INVALID_FORMAT;
    5052                                        gencopy = 0;
    5153                                        mapinshift = genstring.len();
     
    5456                        case '*':
    5557                                genformat = genstring.charAt(2);
     58                                if ((genformat=='\0')||(genformat=='\n'))
     59                                        genformat=INVALID_FORMAT;
    5660                                if ((end = genstring.indexOf("*/")) >= 0)
    5761                                {
    58                                         newcomment = genstring.substr(2, end - 2);
     62                                        if (end!=3) genformat=INVALID_FORMAT;
    5963                                        gencopy = genstring.substr(end + 2);
    6064                                        mapinshift = end + 2;
     
    6266                                else
    6367                                {
     68                                        if (genstring.len()!=5) genformat=INVALID_FORMAT;
    6469                                        gencopy = 0;
    6570                                        mapinshift = genstring.len();
     
    6772                                break;
    6873                        }
    69                         if (newcomment.len() > 0)
    70                         {
    71                                 SString token; int pos = 0;
    72                                 if (newcomment.getNextToken(pos, token, ';'))
    73                                         if (newcomment.getNextToken(pos, token, ';'))
    74                                         {
    75                                                 if (token.len()) txt = token;
    76                                                 if (newcomment.getNextToken(pos, token, ';'))
    77                                                         if (token.len()) name = token;
    78                                         }
    79                         }
    8074                }
    8175        }
     
    8377        gen = gencopy;
    8478        format = genformat;
    85         if (!name.len()) name = genname;
    86         if (!txt.len()) txt = comment;
     79        name = genname;
     80        txt = comment;
    8781        multiline = (strchr(gen.c_str(), '\n') != 0);
    8882        // mapoutshift...?
     
    244238        if (isvalid >= 0) return;
    245239        if (gen.len() == 0) { isvalid = 0; return; }
     240        if (format == INVALID_FORMAT) { isvalid = 0; return; }
    246241        Validators* vals=getValidators();
    247242        if (vals!=NULL)
  • cpp/frams/genetics/geno.h

    r494 r518  
    5555
    5656public:
     57        static const int INVALID_FORMAT='!';
    5758        typedef SListTempl<GenoValidator*> Validators;
    5859
Note: See TracChangeset for help on using the changeset viewer.