Extend commit 25680305095bfcedaa46cb017182544183ab743b to the whole cpu object.
[monky] / src / scroll.c
index 6d10cd7..f78f807 100644 (file)
@@ -9,7 +9,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -60,10 +60,16 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
                sd->step = 1;
        }
        sd->text = malloc(strlen(arg + n1) + sd->show + 1);
-       for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
-               sd->text[n2] = ' ';
+
+       if (strlen(arg) > sd->show) {
+               for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
+                   sd->text[n2] = ' ';
+               }
+               sd->text[n2] = 0;
        }
-       sd->text[n2] = 0;
+       else
+           sd->text[0] = 0;
+
        strcat(sd->text, arg + n1);
        sd->start = 0;
        obj->sub = malloc(sizeof(struct text_object));
@@ -110,7 +116,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor
                        visibcolorchanges++;
                }
                //if there is still room fill it with spaces
-               if( ! p[j]) return;
+               if( ! p[j]) break;
        }
        for(; j < sd->show + visibcolorchanges; j++) {
                p[j] = ' ';
@@ -136,7 +142,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor
        free(pwithcolors);
        //scroll
        sd->start += sd->step;
-       if(buf[sd->start] == 0){
+       if(buf[sd->start] == 0 || sd->start > strlen(buf)){
                sd->start = 0;
        }
 #ifdef X11