diff options
author | Per Bothner <per@bothner.com> | 2004-11-27 22:49:48 -0800 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2004-11-27 22:49:48 -0800 |
commit | ca6b99558d9cbd22bd88c922c629c34a76c27535 (patch) | |
tree | e7ae366f8298db160eb50c0ea514c27c37446d23 /gcc/java/jcf-parse.c | |
parent | ad50046692fd8a85219e5889f59ab03b0d006f1f (diff) | |
download | gcc-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/jcf-parse.c')
-rw-r--r-- | gcc/java/jcf-parse.c | 18 |
1 files changed, 11 insertions, 7 deletions
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); } } |