comparison src/c/urweb.c @ 1105:a5c160636832

Protect against NULL applications in a few places
author Adam Chlipala <adamc@hcoop.net>
date Thu, 31 Dec 2009 15:14:24 -0500
parents 72670131dace
children 631a3597c065
comparison
equal deleted inserted replaced
1104:72670131dace 1105:a5c160636832
448 } 448 }
449 449
450 void uw_set_app(uw_context ctx, uw_app *app) { 450 void uw_set_app(uw_context ctx, uw_app *app) {
451 ctx->app = app; 451 ctx->app = app;
452 452
453 if (app->inputs_len > ctx->sz_inputs) { 453 if (app && app->inputs_len > ctx->sz_inputs) {
454 ctx->sz_inputs = app->inputs_len; 454 ctx->sz_inputs = app->inputs_len;
455 ctx->inputs = realloc(ctx->inputs, ctx->sz_inputs * sizeof(input)); 455 ctx->inputs = realloc(ctx->inputs, ctx->sz_inputs * sizeof(input));
456 memset(ctx->inputs, 0, ctx->sz_inputs * sizeof(input)); 456 memset(ctx->inputs, 0, ctx->sz_inputs * sizeof(input));
457 } 457 }
458 } 458 }
510 ctx->error_message[0] = 0; 510 ctx->error_message[0] = 0;
511 } 511 }
512 512
513 void uw_reset(uw_context ctx) { 513 void uw_reset(uw_context ctx) {
514 uw_reset_keep_request(ctx); 514 uw_reset_keep_request(ctx);
515 memset(ctx->inputs, 0, ctx->app->inputs_len * sizeof(input)); 515 if (ctx->app)
516 memset(ctx->inputs, 0, ctx->app->inputs_len * sizeof(input));
516 memset(ctx->subinputs, 0, ctx->n_subinputs * sizeof(input)); 517 memset(ctx->subinputs, 0, ctx->n_subinputs * sizeof(input));
517 ctx->used_subinputs = 0; 518 ctx->used_subinputs = 0;
518 } 519 }
519 520
520 failure_kind uw_begin_init(uw_context ctx) { 521 failure_kind uw_begin_init(uw_context ctx) {
521 int r = setjmp(ctx->jmp_buf); 522 int r = setjmp(ctx->jmp_buf);
522 523
523 if (r == 0) 524 if (r == 0 && ctx->app)
524 ctx->app->db_init(ctx); 525 ctx->app->db_init(ctx);
525 526
526 return r; 527 return r;
527 } 528 }
528 529