/ Check-in [efb20b9d]
Login

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

Overview
Comment:Add a missing check for out-of-memory in the lemon code generator.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: efb20b9da6c7cb310a449cc818eaccd3d5bb4ab3
User & Date: drh 2011-06-02 15:48:51
Context
2011-06-02
17:24
Fix a faulty assert() in the WAL-mode logic for read-only shared memory. check-in: a13cfe61 user: drh tags: trunk
15:48
Add a missing check for out-of-memory in the lemon code generator. check-in: efb20b9d user: drh tags: trunk
13:04
Merge the read-only shared memory branch into trunk. After this merge, an unprivileged process can open WAL-mode databases owned by another user as long as a database connection with write permission exists on the database file and if the readonly_shm=1 URI query parameter is supplied. check-in: 19084a66 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

  3430   3430     int i,j;                  /* Loop counters */
  3431   3431     int hash;                 /* For hashing the name of a type */
  3432   3432     const char *name;         /* Name of the parser */
  3433   3433   
  3434   3434     /* Allocate and initialize types[] and allocate stddt[] */
  3435   3435     arraysize = lemp->nsymbol * 2;
  3436   3436     types = (char**)calloc( arraysize, sizeof(char*) );
         3437  +  if( types==0 ){
         3438  +    fprintf(stderr,"Out of memory.\n");
         3439  +    exit(1);
         3440  +  }
  3437   3441     for(i=0; i<arraysize; i++) types[i] = 0;
  3438   3442     maxdtlength = 0;
  3439   3443     if( lemp->vartype ){
  3440   3444       maxdtlength = lemonStrlen(lemp->vartype);
  3441   3445     }
  3442   3446     for(i=0; i<lemp->nsymbol; i++){
  3443   3447       int len;
  3444   3448       struct symbol *sp = lemp->symbols[i];
  3445   3449       if( sp->datatype==0 ) continue;
  3446   3450       len = lemonStrlen(sp->datatype);
  3447   3451       if( len>maxdtlength ) maxdtlength = len;
  3448   3452     }
  3449   3453     stddt = (char*)malloc( maxdtlength*2 + 1 );
  3450         -  if( types==0 || stddt==0 ){
         3454  +  if( stddt==0 ){
  3451   3455       fprintf(stderr,"Out of memory.\n");
  3452   3456       exit(1);
  3453   3457     }
  3454   3458   
  3455   3459     /* Build a hash table of datatypes. The ".dtnum" field of each symbol
  3456   3460     ** is filled in with the hash index plus 1.  A ".dtnum" value of 0 is
  3457   3461     ** used for terminal symbols.  If there is no %default_type defined then