Changeset 174 for ttyvaders


Ignore:
Timestamp:
Nov 14, 2003, 6:02:36 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Sanity checks after each malloc() call.
Location:
ttyvaders/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/src/box.c

    r166 r174  
    3030{
    3131    box *b = malloc(sizeof(box));
     32    if(b == NULL)
     33        exit(1);
    3234
    3335    b->x = x;
  • ttyvaders/trunk/src/main.c

    r154 r174  
    3737{
    3838    game *g = malloc(sizeof(game));
     39    if(g == NULL)
     40        exit(1);
    3941
    4042    srand(time(NULL));
     
    7173    g->sf = create_starfield(g);
    7274    g->wp = malloc(sizeof(weapons));
     75    if(g->wp == NULL)
     76        exit(1);
    7377    g->ex = malloc(sizeof(explosions));
     78    if(g->ex == NULL)
     79        exit(1);
    7480    g->bo = malloc(sizeof(bonus));
     81    if(g->bo == NULL)
     82        exit(1);
    7583    g->t = create_tunnel(g, g->w, g->h);
    7684    g->p = create_player(g);
    7785    g->al = malloc(sizeof(aliens));
     86    if(g->al == NULL)
     87        exit(1);
    7888
    7989    init_bonus(g, g->bo);
  • ttyvaders/trunk/src/player.c

    r164 r174  
    3333{
    3434    player *p = malloc(sizeof(player));
     35    if(p == NULL)
     36        exit(1);
    3537
    3638    p->x = g->w / 2;
  • ttyvaders/trunk/src/starfield.c

    r162 r174  
    3333
    3434    s = malloc(STARS * sizeof(starfield));
     35    if(s == NULL)
     36        exit(1);
    3537
    3638    for(i = 0; i < STARS; i++)
  • ttyvaders/trunk/src/tunnel.c

    r154 r174  
    3232    int i;
    3333    tunnel *t = malloc(sizeof(tunnel));
     34    if(t == NULL)
     35        exit(1);
    3436
    3537    t->left = malloc(h*sizeof(int));
     38    if(t->left == NULL)
     39        exit(1);
    3640    t->right = malloc(h*sizeof(int));
     41    if(t->right == NULL)
     42        exit(1);
    3743    t->w = w;
    3844    t->h = h;
  • ttyvaders/trunk/src/weapons.c

    r164 r174  
    170170                if(dx | dy)
    171171                {
    172                     int norm = ee_sqrt(dx * dx + 4 * dy * dy);
     172                    unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy);
    173173                    dx = dx * 32 / norm;
    174174                    dy = dy * 32 / norm;
     
    182182                if(dx | dy)
    183183                {
    184                     int norm = ee_sqrt(dx * dx + 4 * dy * dy);
     184                    unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy);
    185185                    wp->vx[i] = dx * 32 / norm;
    186186                    wp->vy[i] = dy * 32 / norm;
Note: See TracChangeset for help on using the changeset viewer.