changeset 1413:45bd58736bb2

Fix issues with empty page buffers for tasks
author Adam Chlipala <adam@chlipala.net>
date Sun, 23 Jan 2011 14:59:59 -0500
parents 5f4fee8a4dcd
children 8c017e9e410e
files src/c/urweb.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/urweb.c	Sun Jan 23 11:18:24 2011 -0500
+++ b/src/c/urweb.c	Sun Jan 23 14:59:59 2011 -0500
@@ -462,8 +462,10 @@
   ctx->get_header = NULL;
   ctx->get_header_data = NULL;
 
-  uw_buffer_init(uw_headers_max, &ctx->outHeaders, 0);
-  uw_buffer_init(uw_page_max, &ctx->page, 0);
+  uw_buffer_init(uw_headers_max, &ctx->outHeaders, 1);
+  ctx->outHeaders.start[0] = 0;
+  uw_buffer_init(uw_page_max, &ctx->page, 1);
+  ctx->page.start[0] = 0;
   ctx->returning_indirectly = 0;
   uw_buffer_init(uw_heap_max, &ctx->heap, uw_min_heap);
   uw_buffer_init(uw_script_max, &ctx->script, 1);
@@ -1498,10 +1500,11 @@
 
 static void uw_writec_unsafe(uw_context ctx, char c) {
   *(ctx->page.front)++ = c;
+  *ctx->page.front = 0;
 }
 
 void uw_writec(uw_context ctx, char c) {
-  uw_check(ctx, 1);
+  uw_check(ctx, 2);
   uw_writec_unsafe(ctx, c);
 }
 
@@ -3144,6 +3147,9 @@
     if (ctx->transactionals[i].free)
       ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
 
+  if (*ctx->page.front)
+    uw_writec(ctx, 0);
+
   // Splice script data into appropriate part of page
   if (ctx->returning_indirectly || ctx->script_header[0] == 0) {
     char *start = strstr(ctx->page.start, "<sc>");