Changeset 47e0a6a


Ignore:
Timestamp:
Mar 24, 2011, 4:10:53 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
283ff1e
Parents:
d07af84
git-author:
David Benjamin <davidben@mit.edu> (03/11/11 00:17:26)
git-committer:
David Benjamin <davidben@mit.edu> (03/24/11 16:10:53)
Message:
Punt a number of g_new NULL checks, various minor cleanups

No real need to check g_new's return value as it always succeeds. (Or
destroys the universe^Wprocess in embarrassment.) Also make owl_global
manage the lifetime of the kill buffer since it's part of owl_global
now. And replace a g_new/strncpy with a g_strndup. It's shorter.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    rddbbcffa r47e0a6a  
    301301
    302302  if (lock > 0) {
    303     locktext = g_new(char, lock+1);
    304     strncpy(locktext, e->buff, lock);
    305     locktext[lock] = 0;
     303    locktext = g_strndup(e->buff, lock);
    306304  }
    307305
     
    10591057void owl_editwin_yank(owl_editwin *e)
    10601058{
    1061   char *killbuf = owl_global_get_kill_buffer(&g);
     1059  const char *killbuf = owl_global_get_kill_buffer(&g);
    10621060
    10631061  if (killbuf != NULL)
     
    10671065static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len)
    10681066{
    1069   char *p;
    1070   char *killbuf = owl_global_get_kill_buffer(&g);
    1071 
    1072   p = g_new(char, len + 1);
    1073 
    1074   if (p != NULL) {
    1075     g_free(killbuf);
    1076     memcpy(p, buf, len);
    1077     p[len] = 0;
    1078     owl_global_set_kill_buffer(&g,p);
    1079   }
    1080 
    1081   return p;
     1067  owl_global_set_kill_buffer(&g, buf, len);
     1068  return owl_global_get_kill_buffer(&g);
    10821069}
    10831070
  • global.c

    rf25df21 r47e0a6a  
    957957}
    958958
    959 char *owl_global_get_kill_buffer(owl_global *g) {
     959const char *owl_global_get_kill_buffer(owl_global *g) {
    960960  return g->kill_buffer;
    961961}
    962962
    963 void owl_global_set_kill_buffer(owl_global *g,char *kill) {
    964   g->kill_buffer = kill;
    965 }
     963void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
     964  g_free(g->kill_buffer);
     965  g->kill_buffer = g_strndup(kill, len);
     966}
  • keymap.c

    r45e2c95 r47e0a6a  
    197197  owl_keymap *km;
    198198  km = g_new(owl_keymap, 1);
    199   if (!km) return NULL;
    200199  owl_keymap_init(km, name, desc, default_fn, prealways_fn, postalways_fn);
    201200  owl_keyhandler_add_keymap(kh, km);
  • popexec.c

    rddbbcffa r47e0a6a  
    2323
    2424  pe = g_new(owl_popexec, 1);
    25   if (!pe) return NULL;
    2625  pe->winactive=0;
    2726  pe->pid=0;
Note: See TracChangeset for help on using the changeset viewer.