Changeset 822 for cpp/frams


Ignore:
Timestamp:
11/14/18 03:49:59 (5 years ago)
Author:
Maciej Komosinski
Message:

Avoid false positives for script-driven mutable param sanity check ("Invalid ParamEntry? for ExpProperties?.cleardata (no procedure defined)")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/param.cpp

    r805 r822  
    1111#include <frams/util/sstringutils.h>
    1212#include <common/virtfile/stringfile.h>
     13
     14#ifdef _DEBUG
     15//for sanityCheck - mutable param detection
     16#include "mutparamiface.h"
     17#endif
    1318
    1419//#define SAVE_ALL_NAMES
     
    5459                        && (*type(i) != 'p'))
    5560                {
    56                 j = src->findId(id(i));
    57                 if (j < 0) continue;
    58                 src->get(j, v);
    59                 set(i, v);
     61                        j = src->findId(id(i));
     62                        if (j < 0) continue;
     63                        src->get(j, v);
     64                        set(i, v);
    6065                }
    6166}
     
    6974                        && (*type(i) != 'p'))
    7075                {
    71                 src->get(i, v);
    72                 set(i, v);
     76                        src->get(i, v);
     77                        set(i, v);
    7378                }
    7479}
     
    157162                setDouble(i, def);
    158163        }
    159                 break;
     164        break;
    160165        case 'd':
    161166        {
     
    164169                setInt(i, def);
    165170        }
    166                 break;
     171        break;
    167172        case 's': case 'x':
    168173        {
     
    176181                }
    177182        }
    178                 break;
     183        break;
    179184        case 'o':
    180185                setObject(i, ExtObject::empty());
     
    194199                setDouble(i, mn);
    195200        }
    196                 break;
     201        break;
    197202        case 'd':
    198203        {
     
    201206                setInt(i, mn);
    202207        }
    203                 break;
     208        break;
    204209        default: setFromString(i, "", false);
    205210        }
     
    217222                setDouble(i, mx);
    218223        }
    219                 break;
     224        break;
    220225        case 'd':
    221226        {
     
    224229                setInt(i, mx);
    225230        }
    226                 break;
     231        break;
    227232        default: setFromString(i, "", false);
    228233        }
     
    370375                if (!((fl = flags(i))&PARAM_DONTSAVE))
    371376                {
    372                 if (defdata && isequal(i, defdata))
    373                         needlabel = 1;
    374                 else
    375                 {
    376                         if (!first) t += ", ";
     377                        if (defdata && isequal(i, defdata))
     378                                needlabel = 1;
     379                        else
     380                        {
     381                                if (!first) t += ", ";
    377382#ifndef SAVE_ALL_NAMES
    378383#ifdef SAVE_SELECTED_NAMES
    379                         if (needlabel || all_names || !(fl & PARAM_CANOMITNAME))
     384                                if (needlabel || all_names || !(fl & PARAM_CANOMITNAME))
    380385#else
    381                         if (needlabel)
     386                                if (needlabel)
    382387#endif
    383388#endif
    384                         {
    385                                 t += p; t += "="; needlabel = 0;
    386                         }
    387                         if (type(i)[0] == 's')
    388                         { // string - special case
    389                                 SString str = getString(i);
    390                                 if (strContainsOneOf(str.c_str(), ", \\\n\r\t\""))
    391389                                {
    392                                         t += "\"";
    393                                         sstringQuote(str);
    394                                         t += str;
    395                                         t += "\"";
     390                                        t += p; t += "="; needlabel = 0;
     391                                }
     392                                if (type(i)[0] == 's')
     393                                { // string - special case
     394                                        SString str = getString(i);
     395                                        if (strContainsOneOf(str.c_str(), ", \\\n\r\t\""))
     396                                        {
     397                                                t += "\"";
     398                                                sstringQuote(str);
     399                                                t += str;
     400                                                t += "\"";
     401                                        }
     402                                        else
     403                                                t += str;
    396404                                }
    397405                                else
    398                                         t += str;
     406                                        t += get(i);
     407                                first = 0;
    399408                        }
    400                         else
    401                                 t += get(i);
    402                         first = 0;
    403                 }
    404409                }
    405410        if (addcr)
     
    445450                        (setflags&PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
    446451                        ::sstringDelimitAndShorten(actual, 30, show_length, quote, quote).c_str()
    447                         );
     452                );
    448453        }
    449454}
     
    569574                                                if ((tmp = strchr(tmp, '\n')))
    570575                                                {
    571                                                 lfcount++; tmp++;
     576                                                        lfcount++; tmp++;
    572577                                                }
    573578                                        removeCR(s);
     
    606611                                        if ((tmp = strchr(tmp, '\n')))
    607612                                        {
    608                                         lfcount++; tmp++;
     613                                                lfcount++; tmp++;
    609614                                        }
    610615                                (*options.linenum) += lfcount;
     
    834839                if ((have >= 2) && (b < a) && (a != 0) && (b != -1)) return false; // max<min meaning 'undefined' is only allowed as "d 0 -1"
    835840        }
    836                 break;
     841        break;
    837842        case 'f':
    838843        {
     
    842847                if ((have >= 2) && (b < a) && (a != 0) && (b != -1)) return false; // max<min meaning 'undefined' is only allowed as "f 0 -1"
    843848        }
    844                 break;
     849        break;
    845850        case 's':
    846851        {
     
    851856                if ((have >= 2) && (b < 0)) return false; // max=0 means unlimited, max<0 is not allowed
    852857        }
    853                 break;
     858        break;
    854859        }
    855860        return true;
     
    863868        case 'd': t += "integer";
    864869        {paInt a, b, c; int n = getMinMaxIntFromTypeDef(type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %d..%d", a, b); if (n >= 3) t += SString::sprintf(" (default %d)", c); }
    865                 break;
     870        break;
    866871        case 'f': t += "float";
    867872        {double a, b, c; int n = getMinMaxDoubleFromTypeDef(type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %g..%g", a, b); if (n >= 3) t += SString::sprintf(" (default %g)", c); }
    868                 break;
     873        break;
    869874        case 's': t += "string";
    870875        {int a, b; SString c; int n = getMinMaxStringFromTypeDef(type, a, b, c); if ((n >= 2) && (b > 0)) t += SString::sprintf(", max %d chars", b); if (n >= 3) t += SString::sprintf(" (default \"%s\")", c.c_str()); }
    871                 break;
     876        break;
    872877        case 'x': t += "untyped value"; break;
    873878        case 'p': t += "function"; break;
     
    893898        {
    894899                if (pe->fun1 == NULL)
    895                         err = "no procedure defined";
     900                {
     901                        MutableParamInterface *mpi = dynamic_cast<MutableParamInterface*>(this);
     902                        if (mpi == NULL) // Avoid false positives for script-driven mutable params, like expdefs. This can't be reliably verified. Function pointer checking is meant for static param tables anyway so it's probably not a big deal.
     903                                err = "no procedure defined";
     904                }
    896905                if (pe->flags & PARAM_READONLY)
    897906                        err = "function can't be PARAM_READONLY";
     
    911920        if (err != NULL)
    912921                logPrintf("SimpleAbstractParam", "sanityCheck", LOG_ERROR,
    913                 "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err);
     922                        "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err);
    914923}
    915924#endif
     
    10291038                if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking
    10301039                {
    1031                 if (x < mn) { x = mn; result = PSET_HITMIN; }
    1032                 else if (x > mx) { x = mx; result = PSET_HITMAX; }
     1040                        if (x < mn) { x = mn; result = PSET_HITMIN; }
     1041                        else if (x > mx) { x = mx; result = PSET_HITMAX; }
    10331042                }
    10341043
     
    10631072                if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking
    10641073                {
    1065                 if (x < mn) { x = mn; result = PSET_HITMIN; }
    1066                 else if (x > mx) { x = mx; result = PSET_HITMAX; }
     1074                        if (x < mn) { x = mn; result = PSET_HITMIN; }
     1075                        else if (x > mx) { x = mx; result = PSET_HITMAX; }
    10671076                }
    10681077
     
    11451154                else
    11461155                        logPrintf("SimpleAbstractParam", "setObject", LOG_ERROR,
    1147                         "'%s.%s' is PARAM_OBJECTSET but no 'assign()' in %s", getName(), pe->id, o.interfaceName());
     1156                                "'%s.%s' is PARAM_OBJECTSET but no 'assign()' in %s", getName(), pe->id, o.interfaceName());
    11481157                return PSET_CHANGED;
    11491158        }
     
    12631272                field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end;
    12641273                next_field = field_end;
    1265                 while ((field_end>t) && isblank(field_end[-1])) field_end--;
     1274                while ((field_end > t) && isblank(field_end[-1])) field_end--;
    12661275                quote = strchrlimit(t, '\"', field_end);
    12671276                if (quote)
     
    13041313#endif
    13051314                        {
    1306                         if (id(i))
    1307                                 logPrintf("Param", "loadSingleLine", LOG_WARN, "Missing property name in '%s' (assuming '%s')", getName(), id(i));
    1308                         else
    1309                                 logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName());
     1315                                if (id(i))
     1316                                        logPrintf("Param", "loadSingleLine", LOG_WARN, "Missing property name in '%s' (assuming '%s')", getName(), id(i));
     1317                                else
     1318                                        logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName());
    13101319                        }
    13111320#endif
Note: See TracChangeset for help on using the changeset viewer.