[crush-tools] r533 committed - fieldsplit bug fixes:...

9 views
Skip to first unread message

crush...@googlecode.com

unread,
May 2, 2013, 12:25:55 PM5/2/13
to crush...@googlegroups.com
Revision: 533
Author: jeremy...@gmail.com
Date: Thu May 2 09:25:43 2013
Log: fieldsplit bug fixes:

* Do not invoke the regular expression code if -x is not specified.
* Include the binary name in the error message when required args are not
present.
* Clean up some x{re,m}alloc() size args.

http://code.google.com/p/crush-tools/source/detail?r=533

Modified:
/trunk/src/fieldsplit/fieldsplit.c

=======================================
--- /trunk/src/fieldsplit/fieldsplit.c Thu Feb 18 04:39:48 2010
+++ /trunk/src/fieldsplit/fieldsplit.c Thu May 2 09:25:43 2013
@@ -128,7 +128,7 @@
#endif

if (! args->field && ! args->field_label) {
- fprintf(stderr, "%s: either -f or -F must be specified.\n");
+ fprintf(stderr, "%s: either -f or -F must be specified.\n",
getenv("_"));
exit(1);
}

@@ -148,9 +148,9 @@
bucket_len = strlen(args->buckets);
}

- field = xmalloc(128);
- field_key = xmalloc(128);
field_sz = 128;
+ field = xmalloc(field_sz);
+ field_key = xmalloc(field_sz);

#ifdef HAVE_UNISTD_H
max_open_files = sysconf(_SC_OPEN_MAX);
@@ -185,9 +185,9 @@
while (getline(&line, &line_sz, in_file) > 0) {
while (get_line_field(field, line, field_sz,
field_index, args->delim) == field_sz) {
- field = xrealloc(field, field_sz + 32);
- field_key = xrealloc(field_key, field_sz + 32);
- field_sz += 32;
+ field_sz *= 2;
+ field = xrealloc(field, field_sz);
+ field_key = xrealloc(field_key, field_sz);
}
transform_key(field, field_key, &subst_buffer, &subst_buffer_sz);
if (buckets) {
@@ -232,10 +232,14 @@
p++;
}
#ifdef HAVE_PCRE_H
- crush_re_substitute(re, re_extra, compiled_subst, n_subst_elems,
- copy, re_subst, subst_buffer, subst_buffer_sz,
- subst_globally);
- strcpy(copy, *subst_buffer);
+ if (re) {
+ crush_re_substitute(re, re_extra, compiled_subst, n_subst_elems,
+ copy, re_subst, subst_buffer, subst_buffer_sz,
+ subst_globally);
+ /* TODO(jhinds): this can overflow if the substitution results in a
+ * longer string than the original. */
+ strcpy(copy, *subst_buffer);
+ }
#endif
return copy;
}
Reply all
Reply to author
Forward
0 new messages