aboutsummaryrefslogtreecommitdiff
path: root/gcc/java
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>2004-11-27 22:49:48 -0800
committerPer Bothner <bothner@gcc.gnu.org>2004-11-27 22:49:48 -0800
commitca6b99558d9cbd22bd88c922c629c34a76c27535 (patch)
treee7ae366f8298db160eb50c0ea514c27c37446d23 /gcc/java
parentad50046692fd8a85219e5889f59ab03b0d006f1f (diff)
downloadgcc-ca6b99558d9cbd22bd88c922c629c34a76c27535.zip
gcc-ca6b99558d9cbd22bd88c922c629c34a76c27535.tar.gz
gcc-ca6b99558d9cbd22bd88c922c629c34a76c27535.tar.bz2
jcf-parse.c (set_source_filename): Improvement to Andrew's fix...
* 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. From-SVN: r91411
Diffstat (limited to 'gcc/java')
-rw-r--r--gcc/java/ChangeLog7
-rw-r--r--gcc/java/jcf-parse.c18
2 files changed, 18 insertions, 7 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 0d65ea1..c79a758 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,5 +1,12 @@
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
local static variables if not USE_MAPPED_LOCATION.
diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c
index 429e3db..8171522 100644
--- a/gcc/java/jcf-parse.c
+++ b/gcc/java/jcf-parse.c
@@ -151,18 +151,22 @@ set_source_filename (JCF *jcf, int index)
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);
}
}