+2004-11-27 Per Bothner <per@bothner.com>
+
+ * jcf-parse.c (set_source_filename): Improvement to Andrew's fix:
+ Fix fencepost error in 'i', which got executed one too many times.
+ Also, fold memcpy into explicit loop, as originally intended.
+ Also, free temporary 'buf' which otherwise leaks.
+
2004-11-27 Per Bothner <per@bothner.com>
* expr.c (build_expr_wfl): Only declare last_file and last_filenode
char *dot = strrchr (class_name, '.');
if (dot != NULL)
{
- int i = dot - class_name + 1;
+ /* Length of prefix, not counting final dot. */
+ int i = dot - class_name;
/* Concatenate current package prefix with new sfname. */
- char *buf = xmalloc (i+new_len+3);
- memcpy (buf, class_name, i);
- strcpy (buf + i, sfname);
- /* Replace '.' by DIR_SEPARATOR. */
+ char *buf = xmalloc (i + new_len + 2); /* Space for '.' and '\0'. */
+ strcpy (buf + i + 1, sfname);
+ /* Copy package from class_name, replacing '.' by DIR_SEPARATOR.
+ Note we start at the end with the final package dot. */
for (; i >= 0; i--)
{
- if (buf[i] == '.')
- buf[i] = DIR_SEPARATOR;
+ char c = class_name[i];
+ if (c == '.')
+ c = DIR_SEPARATOR;
+ buf[i] = c;
}
sfname_id = get_identifier (buf);
+ free (buf);
sfname = IDENTIFIER_POINTER (sfname_id);
}
}