Changeset 0290b2a


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
c6b1782
Parents:
df3a1f4
git-author:
David Benjamin <davidben@mit.edu> (01/24/11 23:31:49)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Use GString instead of allocating a giant buffer in owl_parseline
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    r65c753e r0290b2a  
    112112  GPtrArray *argv;
    113113  int i, len, between=1;
    114   char *curarg;
     114  GString *curarg;
    115115  char quote;
    116116
    117117  argv = g_ptr_array_new_with_free_func(owl_free);
    118118  len=strlen(line);
    119   curarg=owl_malloc(len+10);
    120   strcpy(curarg, "");
     119  curarg = g_string_new("");
    121120  quote='\0';
    122121  *argc=0;
     
    148147
    149148      /* if another type of quote is open then treat this as a literal */
    150       curarg[strlen(curarg)+1]='\0';
    151       curarg[strlen(curarg)]=line[i];
     149      g_string_append_c(curarg, line[i]);
    152150      continue;
    153151    }
     
    155153    /* if it's not a space or end of command, then use it */
    156154    if (line[i]!=' ' && line[i]!='\t' && line[i]!='\n' && line[i]!='\0') {
    157       curarg[strlen(curarg)+1]='\0';
    158       curarg[strlen(curarg)]=line[i];
     155      g_string_append_c(curarg, line[i]);
    159156      continue;
    160157    }
     
    163160    if (quote=='\0') {
    164161      /* add the argument */
    165       g_ptr_array_add(argv, owl_strdup(curarg));
    166       strcpy(curarg, "");
     162      g_ptr_array_add(argv, g_string_free(curarg, false));
     163      curarg = g_string_new("");
    167164      between=1;
    168165      continue;
     
    170167
    171168    /* if it is a space and we're in quotes, then use it */
    172     curarg[strlen(curarg)+1]='\0';
    173     curarg[strlen(curarg)]=line[i];
     169    g_string_append_c(curarg, line[i]);
    174170  }
    175171
    176172  *argc = argv->len;
    177173  g_ptr_array_add(argv, NULL);
    178   owl_free(curarg);
     174  g_string_free(curarg, true);
    179175
    180176  /* check for unbalanced quotes */
Note: See TracChangeset for help on using the changeset viewer.