changeset 28182:26ab2d01157f

Add asserts to detect when assumptions for play_tree_parser_get_line fail (mostly due to parsers using it incorrectly).
author reimar
date Thu, 01 Jan 2009 09:35:25 +0000
parents a02653498c15
children b197740bf718
files playtreeparser.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/playtreeparser.c	Wed Dec 31 14:21:50 2008 +0000
+++ b/playtreeparser.c	Thu Jan 01 09:35:25 2009 +0000
@@ -6,9 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#ifdef MP_DEBUG
 #include <assert.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -61,6 +59,8 @@
   if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0'))
     return NULL;
     
+  assert(p->buffer_end < p->buffer_size);
+  assert(!p->buffer[p->buffer_end]);
   while(1) {
 
     if(resize) {
@@ -75,10 +75,12 @@
       r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1);
       if(r > 0) {
 	p->buffer_end += r;
+	assert(p->buffer_end < p->buffer_size);
 	p->buffer[p->buffer_end] = '\0';
 	while(strlen(p->buffer + p->buffer_end - r) != r)
 	  p->buffer[p->buffer_end - r + strlen(p->buffer + p->buffer_end - r)] = '\n';
       }
+      assert(!p->buffer[p->buffer_end]);
     }
     
     end = strchr(p->iter,'\n');