/ Check-in [a519cdb2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Explicit casts of the return from strlen() to int in lemon. This has no effect on SQLite. It has no effect on any lemon-generated parser with a grammar that is less than 2GB in size. Ticket #3293. (CVS 5564)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a519cdb2f46fffe16e666f161479a22463616cb3
User & Date: drh 2008-08-13 20:09:07
Context
2008-08-14
00:19
Do not flatten the right term of a LEFT join. Ticket #3300. (CVS 5565) check-in: 8947c72f user: drh tags: trunk
2008-08-13
20:09
Explicit casts of the return from strlen() to int in lemon. This has no effect on SQLite. It has no effect on any lemon-generated parser with a grammar that is less than 2GB in size. Ticket #3293. (CVS 5564) check-in: a519cdb2 user: drh tags: trunk
20:04
Fix token destructors in lemon generated parsers. Does not effect SQLite. Ticket #3299. (CVS 5563) check-in: 4887e8fc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

    32     32   #define MAXRHS 5       /* Set low to exercise exception code */
    33     33   #else
    34     34   #define MAXRHS 1000
    35     35   #endif
    36     36   
    37     37   static char *msort(char*,char**,int(*)(const char*,const char*));
    38     38   
           39  +/*
           40  +** Compilers are getting increasingly pedantic about type conversions
           41  +** as C evolves ever closer to Ada....  To work around the latest problems
           42  +** we have to define the following variant of strlen().
           43  +*/
           44  +#define lemonStrlen(X)   ((int)strlen(X))
           45  +
    39     46   static struct action *Action_new(void);
    40     47   static struct action *Action_sort(struct action *);
    41     48   
    42     49   /********** From the file "build.h" ************************************/
    43     50   void FindRulePrecedences();
    44     51   void FindFirstSets();
    45     52   void FindStates();
................................................................................
  1317   1324     va_start(ap, format);
  1318   1325     /* Prepare a prefix to be prepended to every output line */
  1319   1326     if( lineno>0 ){
  1320   1327       sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno);
  1321   1328     }else{
  1322   1329       sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename);
  1323   1330     }
  1324         -  prefixsize = strlen(prefix);
         1331  +  prefixsize = lemonStrlen(prefix);
  1325   1332     availablewidth = LINEWIDTH - prefixsize;
  1326   1333   
  1327   1334     /* Generate the error message */
  1328   1335     vsprintf(errmsg,format,ap);
  1329   1336     va_end(ap);
  1330         -  errmsgsize = strlen(errmsg);
         1337  +  errmsgsize = lemonStrlen(errmsg);
  1331   1338     /* Remove trailing '\n's from the error message. */
  1332   1339     while( errmsgsize>0 && errmsg[errmsgsize-1]=='\n' ){
  1333   1340        errmsg[--errmsgsize] = 0;
  1334   1341     }
  1335   1342   
  1336   1343     /* Print the error message */
  1337   1344     base = 0;
................................................................................
  1367   1374     nDefine++;
  1368   1375     azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine);
  1369   1376     if( azDefine==0 ){
  1370   1377       fprintf(stderr,"out of memory\n");
  1371   1378       exit(1);
  1372   1379     }
  1373   1380     paz = &azDefine[nDefine-1];
  1374         -  *paz = malloc( strlen(z)+1 );
         1381  +  *paz = malloc( lemonStrlen(z)+1 );
  1375   1382     if( *paz==0 ){
  1376   1383       fprintf(stderr,"out of memory\n");
  1377   1384       exit(1);
  1378   1385     }
  1379   1386     strcpy(*paz, z);
  1380   1387     for(z=*paz; *z && *z!='='; z++){}
  1381   1388     *z = 0;
................................................................................
  1645   1652   static void errline(n,k,err)
  1646   1653   int n;
  1647   1654   int k;
  1648   1655   FILE *err;
  1649   1656   {
  1650   1657     int spcnt, i;
  1651   1658     if( argv[0] ) fprintf(err,"%s",argv[0]);
  1652         -  spcnt = strlen(argv[0]) + 1;
         1659  +  spcnt = lemonStrlen(argv[0]) + 1;
  1653   1660     for(i=1; i<n && argv[i]; i++){
  1654   1661       fprintf(err," %s",argv[i]);
  1655         -    spcnt += strlen(argv[i])+1;
         1662  +    spcnt += lemonStrlen(argv[i])+1;
  1656   1663     }
  1657   1664     spcnt += k;
  1658   1665     for(; argv[i]; i++) fprintf(err," %s",argv[i]);
  1659   1666     if( spcnt<20 ){
  1660   1667       fprintf(err,"\n%*s^-- here\n",spcnt,"");
  1661   1668     }else{
  1662   1669       fprintf(err,"\n%*shere --^\n",spcnt-7,"");
................................................................................
  1693   1700   int i;
  1694   1701   FILE *err;
  1695   1702   {
  1696   1703     int v;
  1697   1704     int errcnt = 0;
  1698   1705     int j;
  1699   1706     for(j=0; op[j].label; j++){
  1700         -    if( strncmp(&argv[i][1],op[j].label,strlen(op[j].label))==0 ) break;
         1707  +    if( strncmp(&argv[i][1],op[j].label,lemonStrlen(op[j].label))==0 ) break;
  1701   1708     }
  1702   1709     v = argv[i][0]=='-' ? 1 : 0;
  1703   1710     if( op[j].label==0 ){
  1704   1711       if( err ){
  1705   1712         fprintf(err,"%sundefined option.\n",emsg);
  1706   1713         errline(i,1,err);
  1707   1714       }
................................................................................
  1870   1877   }
  1871   1878   
  1872   1879   void OptPrint(){
  1873   1880     int i;
  1874   1881     int max, len;
  1875   1882     max = 0;
  1876   1883     for(i=0; op[i].label; i++){
  1877         -    len = strlen(op[i].label) + 1;
         1884  +    len = lemonStrlen(op[i].label) + 1;
  1878   1885       switch( op[i].type ){
  1879   1886         case OPT_FLAG:
  1880   1887         case OPT_FFLAG:
  1881   1888           break;
  1882   1889         case OPT_INT:
  1883   1890         case OPT_FINT:
  1884   1891           len += 9;       /* length of "<integer>" */
................................................................................
  1899   1906         case OPT_FLAG:
  1900   1907         case OPT_FFLAG:
  1901   1908           fprintf(errstream,"  -%-*s  %s\n",max,op[i].label,op[i].message);
  1902   1909           break;
  1903   1910         case OPT_INT:
  1904   1911         case OPT_FINT:
  1905   1912           fprintf(errstream,"  %s=<integer>%*s  %s\n",op[i].label,
  1906         -          (int)(max-strlen(op[i].label)-9),"",op[i].message);
         1913  +          (int)(max-lemonStrlen(op[i].label)-9),"",op[i].message);
  1907   1914           break;
  1908   1915         case OPT_DBL:
  1909   1916         case OPT_FDBL:
  1910   1917           fprintf(errstream,"  %s=<real>%*s  %s\n",op[i].label,
  1911         -          (int)(max-strlen(op[i].label)-6),"",op[i].message);
         1918  +          (int)(max-lemonStrlen(op[i].label)-6),"",op[i].message);
  1912   1919           break;
  1913   1920         case OPT_STR:
  1914   1921         case OPT_FSTR:
  1915   1922           fprintf(errstream,"  %s=<string>%*s  %s\n",op[i].label,
  1916         -          (int)(max-strlen(op[i].label)-8),"",op[i].message);
         1923  +          (int)(max-lemonStrlen(op[i].label)-8),"",op[i].message);
  1917   1924           break;
  1918   1925       }
  1919   1926     }
  1920   1927   }
  1921   1928   /*********************** From the file "parse.c" ****************************/
  1922   1929   /*
  1923   1930   ** Input file parser for the LEMON parser generator.
................................................................................
  2321   2328         if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
  2322   2329           char *zOld, *zNew, *zBuf, *z;
  2323   2330           int nOld, n, nLine, nNew, nBack;
  2324   2331           int addLineMacro;
  2325   2332           char zLine[50];
  2326   2333           zNew = x;
  2327   2334           if( zNew[0]=='"' || zNew[0]=='{' ) zNew++;
  2328         -        nNew = strlen(zNew);
         2335  +        nNew = lemonStrlen(zNew);
  2329   2336           if( *psp->declargslot ){
  2330   2337             zOld = *psp->declargslot;
  2331   2338           }else{
  2332   2339             zOld = "";
  2333   2340           }
  2334         -        nOld = strlen(zOld);
         2341  +        nOld = lemonStrlen(zOld);
  2335   2342           n = nOld + nNew + 20;
  2336   2343           addLineMacro = psp->insertLineMacro &&
  2337   2344                           (psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
  2338   2345           if( addLineMacro ){
  2339   2346             for(z=psp->filename, nBack=0; *z; z++){
  2340   2347               if( *z=='\\' ) nBack++;
  2341   2348             }
  2342   2349             sprintf(zLine, "#line %d ", psp->tokenlineno);
  2343         -          nLine = strlen(zLine);
  2344         -          n += nLine + strlen(psp->filename) + nBack;
         2350  +          nLine = lemonStrlen(zLine);
         2351  +          n += nLine + lemonStrlen(psp->filename) + nBack;
  2345   2352           }
  2346   2353           *psp->declargslot = zBuf = realloc(*psp->declargslot, n);
  2347   2354           zBuf += nOld;
  2348   2355           if( addLineMacro ){
  2349   2356             if( nOld && zBuf[-1]!='\n' ){
  2350   2357               *(zBuf++) = '\n';
  2351   2358             }
................................................................................
  2451   2458         if( exclude ){
  2452   2459           exclude++;
  2453   2460         }else{
  2454   2461           for(j=i+7; isspace(z[j]); j++){}
  2455   2462           for(n=0; z[j+n] && !isspace(z[j+n]); n++){}
  2456   2463           exclude = 1;
  2457   2464           for(k=0; k<nDefine; k++){
  2458         -          if( strncmp(azDefine[k],&z[j],n)==0 && strlen(azDefine[k])==n ){
         2465  +          if( strncmp(azDefine[k],&z[j],n)==0 && lemonStrlen(azDefine[k])==n ){
  2459   2466               exclude = 0;
  2460   2467               break;
  2461   2468             }
  2462   2469           }
  2463   2470           if( z[i+3]=='n' ) exclude = !exclude;
  2464   2471           if( exclude ){
  2465   2472             start = i;
................................................................................
  2705   2712   PRIVATE char *file_makename(lemp,suffix)
  2706   2713   struct lemon *lemp;
  2707   2714   char *suffix;
  2708   2715   {
  2709   2716     char *name;
  2710   2717     char *cp;
  2711   2718   
  2712         -  name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );
         2719  +  name = malloc( lemonStrlen(lemp->filename) + lemonStrlen(suffix) + 5 );
  2713   2720     if( name==0 ){
  2714   2721       fprintf(stderr,"Can't allocate space for a filename.\n");
  2715   2722       exit(1);
  2716   2723     }
  2717   2724     strcpy(name,lemp->filename);
  2718   2725     cp = strrchr(name,'.');
  2719   2726     if( cp ) *cp = 0;
................................................................................
  2750   2757     struct rule *rp;
  2751   2758     struct symbol *sp;
  2752   2759     int i, j, maxlen, len, ncolumns, skip;
  2753   2760     printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename);
  2754   2761     maxlen = 10;
  2755   2762     for(i=0; i<lemp->nsymbol; i++){
  2756   2763       sp = lemp->symbols[i];
  2757         -    len = strlen(sp->name);
         2764  +    len = lemonStrlen(sp->name);
  2758   2765       if( len>maxlen ) maxlen = len;
  2759   2766     }
  2760   2767     ncolumns = 76/(maxlen+5);
  2761   2768     if( ncolumns<1 ) ncolumns = 1;
  2762   2769     skip = (lemp->nsymbol + ncolumns - 1)/ncolumns;
  2763   2770     for(i=0; i<skip; i++){
  2764   2771       printf("//");
................................................................................
  2965   2972     cp = strrchr(argv0,'\\');
  2966   2973   #else
  2967   2974     cp = strrchr(argv0,'/');
  2968   2975   #endif
  2969   2976     if( cp ){
  2970   2977       c = *cp;
  2971   2978       *cp = 0;
  2972         -    path = (char *)malloc( strlen(argv0) + strlen(name) + 2 );
         2979  +    path = (char *)malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 );
  2973   2980       if( path ) sprintf(path,"%s/%s",argv0,name);
  2974   2981       *cp = c;
  2975   2982     }else{
  2976   2983       extern char *getenv();
  2977   2984       pathlist = getenv("PATH");
  2978   2985       if( pathlist==0 ) pathlist = ".:/bin:/usr/bin";
  2979         -    path = (char *)malloc( strlen(pathlist)+strlen(name)+2 );
         2986  +    path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 );
  2980   2987       if( path!=0 ){
  2981   2988         while( *pathlist ){
  2982   2989           cp = strchr(pathlist,':');
  2983         -        if( cp==0 ) cp = &pathlist[strlen(pathlist)];
         2990  +        if( cp==0 ) cp = &pathlist[lemonStrlen(pathlist)];
  2984   2991           c = *cp;
  2985   2992           *cp = 0;
  2986   2993           sprintf(path,"%s/%s",pathlist,name);
  2987   2994           *cp = c;
  2988   2995           if( c==0 ) pathlist = "";
  2989   2996           else pathlist = &cp[1];
  2990   2997           if( access(path,modemask)==0 ) break;
................................................................................
  3211   3218       return z;
  3212   3219     }
  3213   3220     if( n<=0 ){
  3214   3221       if( n<0 ){
  3215   3222         used += n;
  3216   3223         assert( used>=0 );
  3217   3224       }
  3218         -    n = strlen(zText);
         3225  +    n = lemonStrlen(zText);
  3219   3226     }
  3220   3227     if( n+sizeof(zInt)*2+used >= alloced ){
  3221   3228       alloced = n + sizeof(zInt)*2 + used + 200;
  3222   3229       z = realloc(z,  alloced);
  3223   3230     }
  3224   3231     if( z==0 ) return "";
  3225   3232     while( n-- > 0 ){
  3226   3233       c = *(zText++);
  3227   3234       if( c=='%' && n>0 && zText[0]=='d' ){
  3228   3235         sprintf(zInt, "%d", p1);
  3229   3236         p1 = p2;
  3230   3237         strcpy(&z[used], zInt);
  3231         -      used += strlen(&z[used]);
         3238  +      used += lemonStrlen(&z[used]);
  3232   3239         zText++;
  3233   3240         n--;
  3234   3241       }else{
  3235   3242         z[used++] = c;
  3236   3243       }
  3237   3244     }
  3238   3245     z[used] = 0;
................................................................................
  3380   3387   
  3381   3388     /* Allocate and initialize types[] and allocate stddt[] */
  3382   3389     arraysize = lemp->nsymbol * 2;
  3383   3390     types = (char**)calloc( arraysize, sizeof(char*) );
  3384   3391     for(i=0; i<arraysize; i++) types[i] = 0;
  3385   3392     maxdtlength = 0;
  3386   3393     if( lemp->vartype ){
  3387         -    maxdtlength = strlen(lemp->vartype);
         3394  +    maxdtlength = lemonStrlen(lemp->vartype);
  3388   3395     }
  3389   3396     for(i=0; i<lemp->nsymbol; i++){
  3390   3397       int len;
  3391   3398       struct symbol *sp = lemp->symbols[i];
  3392   3399       if( sp->datatype==0 ) continue;
  3393         -    len = strlen(sp->datatype);
         3400  +    len = lemonStrlen(sp->datatype);
  3394   3401       if( len>maxdtlength ) maxdtlength = len;
  3395   3402     }
  3396   3403     stddt = (char*)malloc( maxdtlength*2 + 1 );
  3397   3404     if( types==0 || stddt==0 ){
  3398   3405       fprintf(stderr,"Out of memory.\n");
  3399   3406       exit(1);
  3400   3407     }
................................................................................
  3438   3445           break;
  3439   3446         }
  3440   3447         hash++;
  3441   3448         if( hash>=arraysize ) hash = 0;
  3442   3449       }
  3443   3450       if( types[hash]==0 ){
  3444   3451         sp->dtnum = hash + 1;
  3445         -      types[hash] = (char*)malloc( strlen(stddt)+1 );
         3452  +      types[hash] = (char*)malloc( lemonStrlen(stddt)+1 );
  3446   3453         if( types[hash]==0 ){
  3447   3454           fprintf(stderr,"Out of memory.\n");
  3448   3455           exit(1);
  3449   3456         }
  3450   3457         strcpy(types[hash],stddt);
  3451   3458       }
  3452   3459     }
................................................................................
  3607   3614     fprintf(out, "#endif\n"); lineno++;
  3608   3615     if( mhflag ){
  3609   3616       fprintf(out,"#if INTERFACE\n"); lineno++;
  3610   3617     }
  3611   3618     name = lemp->name ? lemp->name : "Parse";
  3612   3619     if( lemp->arg && lemp->arg[0] ){
  3613   3620       int i;
  3614         -    i = strlen(lemp->arg);
         3621  +    i = lemonStrlen(lemp->arg);
  3615   3622       while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
  3616   3623       while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
  3617   3624       fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg);  lineno++;
  3618   3625       fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg);  lineno++;
  3619   3626       fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n",
  3620   3627                    name,lemp->arg,&lemp->arg[i]);  lineno++;
  3621   3628       fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n",
................................................................................
  4205   4212   char *Strsafe(y)
  4206   4213   char *y;
  4207   4214   {
  4208   4215     char *z;
  4209   4216   
  4210   4217     if( y==0 ) return 0;
  4211   4218     z = Strsafe_find(y);
  4212         -  if( z==0 && (z=malloc( strlen(y)+1 ))!=0 ){
         4219  +  if( z==0 && (z=malloc( lemonStrlen(y)+1 ))!=0 ){
  4213   4220       strcpy(z,y);
  4214   4221       Strsafe_insert(z);
  4215   4222     }
  4216   4223     MemoryCheck(z);
  4217   4224     return z;
  4218   4225   }
  4219   4226