Changeset 0504f63 for filter.c


Ignore:
Timestamp:
Aug 10, 2008, 5:38:44 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e9bb404
Parents:
d81f8d0
Message:
Rewrite owl_filter_print to use GString.

barnowl will no longer segfault on `show filter' with filters over
5000 characters or so.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r601733d r0504f63  
    212212
    213213
    214 void owl_filter_print(owl_filter *f, char *out)
    215 {
    216   strcpy(out, owl_filter_get_name(f));
    217   strcat(out, ": ");
     214char* owl_filter_print(owl_filter *f)
     215{
     216  GString *out = g_string_new(owl_filter_get_name(f));
     217
     218  g_string_append(out, ": ");
    218219
    219220  if (f->fgcolor!=OWL_COLOR_DEFAULT) {
    220     strcat(out, "-c ");
     221    g_string_append(out, "-c ");
    221222    if (f->fgcolor < 8) {
    222       strcat(out, owl_util_color_to_string(f->fgcolor));
     223      g_string_append(out, owl_util_color_to_string(f->fgcolor));
    223224    }
    224225    else {
    225       char* c = owl_sprintf("%i",f->fgcolor);
    226       strcat(out, c);
    227       owl_free(c);
    228     }
    229     strcat(out, " ");
     226      g_string_append_printf(out, "%i",f->fgcolor);
     227    }
     228    g_string_append(out, " ");
    230229  }
    231230  if (f->bgcolor!=OWL_COLOR_DEFAULT) {
    232     strcat(out, "-b ");
     231    g_string_append(out, "-b ");
    233232    if (f->bgcolor < 8) {
    234       strcat(out, owl_util_color_to_string(f->bgcolor));
     233      g_string_append(out, owl_util_color_to_string(f->bgcolor));
    235234    }
    236235    else {
    237       char* c = owl_sprintf("%i",f->bgcolor);
    238       strcat(out, c);
    239       owl_free(c);
    240     }
    241     strcat(out, " ");
    242   }
    243   if(!f->root) return;
    244   owl_filterelement_print(f->root, out);
    245   strcat(out, "\n");
     236      g_string_append_printf(out, "%i",f->fgcolor);
     237    }
     238    g_string_append(out, " ");
     239  }
     240  if(f->root) {
     241    owl_filterelement_print(f->root, out);
     242    g_string_append(out, "\n");
     243  }
     244
     245  return g_string_free(out, 0);
    246246}
    247247
     
    249249int owl_filter_equiv(owl_filter *a, owl_filter *b)
    250250{
    251   char buff[LINE], buff2[LINE];
    252 
    253   owl_filter_print(a, buff);
    254   owl_filter_print(b, buff2);
    255 
    256   if (!strcmp(buff, buff2)) return(1);
    257   return(0);
     251  char *buffa, *buffb;
     252  int ret;
     253
     254  buffa = owl_filter_print(a);
     255  buffb = owl_filter_print(b);
     256
     257  ret = !strcmp(buffa, buffb);
     258
     259  owl_free(buffa);
     260  owl_free(buffb);
     261
     262  return ret;
    258263}
    259264
Note: See TracChangeset for help on using the changeset viewer.