Changeset 30


Ignore:
Timestamp:
Mar 1, 2008, 2:58:14 PM (10 years ago)
Author:
Sam Hocevar
Message:
  • Fix heap corruption and resulting at-exit crash, thanks to Kees Cook.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/include/stack.hpp

    r2 r30  
    1515  T **sdata;
    1616  long son;
     17  long smax;
    1718
    18   grow_stack(int max_size) { sdata=(T **)jmalloc(max_size,"pointer stack");  son=0; }
     19  grow_stack(int max_size) {
     20    smax=max_size;
     21    son=0;
     22    sdata=(T **)jmalloc(sizeof(T *)*smax,"pointer stack");
     23  }
    1924  void push(T *data)
    2025  {
     26    if (son>=smax) { lbreak("stack overflow (%ld)\n",smax); exit(1); }
    2127    sdata[son]=data;
    2228    son++;
     
    2430   
    2531  T *pop(long total)
    26   { if (total>son) { lbreak("stack underflow\n"); exit(0); }
     32  { if (total>son) { lbreak("stack underflow\n"); exit(1); }
    2733    son-=total;
    2834    return sdata[son];
Note: See TracChangeset for help on using the changeset viewer.