bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variables in yyparse


From: Laurence Finston
Subject: Re: variables in yyparse
Date: Mon, 20 Dec 2004 18:16:06 +0100 (MET)

Using the code below, I have determined that on the system
I'm using, `new char[k]' successfully allocates memory once
for k == 2145169388 but fails to do so for k == 2145169389.
These values are > 2^30 and < 2^31, which is a healthy
chunk of memory.  `bad_alloc' is thrown;  a segment
violation error is not signalled.

Laurence

/* tstbadal.c++ */
/* Created by Laurence Finston 2004.12.20.  */

#include <exception>
#include <float.h>
#include <ios>
#include <iostream>
#include <new>
#include <stdio.h>
#include <stdlib.h>

   using namespace std;

int
main(int argc, char** argv)
{

   char* c = 0;
   int j  = 0;
   unsigned int k[3];

   k[0] = static_cast<unsigned int>(pow(2.0, 30));
   k[1] = static_cast<unsigned int>(pow(2.0, 31));

   /*
    *********************************************
        PC Pentium II XEON, SUSE Linux (unknown version).

        (k[0] == 2^30 == 1073741824)
      < (k[2]         == 2145169388)
      < (k[1] == 2^31 == 2147483648)


      (- 2147483648 2145169388) == 2314259.  I don't know the
      significance, if any, of this number.

      No command-line argument:
       k[2] == 2145169388:  Fails after 1 iteration

      Any command-line argument:
       k[2] == 2145169389:  Fails immediately (0 iterations)

   *********************************************
   */

    k[2] = 2145169389;

    if (argc > 1)
      ;
    else
       k[2] -= 1;

    cerr << "`k[0]' == " << k[0] << endl
         << "`k[2]' == " << k[2] << endl
         << "`k[1]' == " << k[1] << endl;

   for (;;)
     {

       try
         {
           c = new char[k[2]];
           ++j;
         }

       catch (bad_alloc)
         {

           cerr << "`bad_alloc' after " << j << " iterations." << endl;

           break;

         }

     } /* |for|  */



   return 0;

}  /* End of |main()| definition.  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]