Changeset 45e2c95


Ignore:
Timestamp:
Mar 24, 2011, 4:09:22 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
d07af84
Parents:
b13daa0
git-author:
David Benjamin <davidben@mit.edu> (03/10/11 15:45:00)
git-committer:
David Benjamin <davidben@mit.edu> (03/24/11 16:09:22)
Message:
Don't pass limited buffer lengths to owl_keybinding_tostring

The keymap tostring code still probably should be cleaned up though.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • keybinding.c

    rb13daa0 r45e2c95  
    8585}
    8686
    87 /* returns 0 on success */
    88 int owl_keybinding_stack_tostring(int *j, int len, char *buff, int bufflen)
     87char *owl_keybinding_stack_tostring(int *j, int len)
    8988{
    90   char *pos = buff;
    91   int   rem = bufflen;
    92   int   i, n;
     89  GString *string;
     90  char keypress[64];  /* TODO: don't hard-code a value here. */
     91  int  i;
    9392
    94   for (i=0; i < len; i++) {
    95     owl_keypress_tostring(j[i], 0, pos, rem-1);
    96     if (i < len - 1) strcat(pos, " ");
    97     n = strlen(pos);
    98     pos += n;
    99     rem -= n;
     93  string = g_string_new("");
     94  for (i = 0; i < len; i++) {
     95    owl_keypress_tostring(j[i], 0, keypress, sizeof(keypress));
     96    g_string_append(string, keypress);
     97    if (i < len - 1) g_string_append_c(string, ' ');
    10098  }
    101   return 0;
     99  return g_string_free(string, false);
    102100}
    103101
    104 /* returns 0 on success */
    105 int owl_keybinding_tostring(const owl_keybinding *kb, char *buff, int bufflen)
     102char *owl_keybinding_tostring(const owl_keybinding *kb)
    106103{
    107   return owl_keybinding_stack_tostring(kb->keys, kb->len, buff, bufflen);
     104  return owl_keybinding_stack_tostring(kb->keys, kb->len);
    108105}
    109106
  • keymap.c

    rb13daa0 r45e2c95  
    144144  nbindings = owl_list_get_size(&km->bindings);
    145145  for (i=0; i<nbindings; i++) {
    146     char buff[100];
     146    char *kbstr;
    147147    const owl_cmd *cmd;
    148148    const char *tmpdesc, *desc = "";
    149149
    150150    kb = owl_list_get_element(&km->bindings, i);
    151     owl_keybinding_tostring(kb, buff, 100);
     151    kbstr = owl_keybinding_tostring(kb);
    152152    owl_fmtext_append_normal(fm, OWL_TABSTR);
    153     owl_fmtext_append_normal(fm, buff);
    154     owl_fmtext_append_spaces(fm, 11-strlen(buff));
     153    owl_fmtext_append_normal(fm, kbstr);
     154    owl_fmtext_append_spaces(fm, 11-strlen(kbstr));
     155    g_free(kbstr);
    155156    owl_fmtext_append_normal(fm, " - ");
    156157    if (kb->desc && *kb->desc) {
     
    313314void owl_keyhandler_invalidkey(owl_keyhandler *kh)
    314315{
    315     char kbbuff[500];
    316     owl_keybinding_stack_tostring(kh->kpstack, kh->kpstackpos+1, kbbuff, 500);
     316    char *kbbuff = owl_keybinding_stack_tostring(kh->kpstack, kh->kpstackpos+1);
    317317    owl_function_makemsg("'%s' is not a valid key in this context.", kbbuff);
     318    g_free(kbbuff);
    318319    owl_keyhandler_reset(kh);
    319320}
Note: See TracChangeset for help on using the changeset viewer.