This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [patch] fastjar fix off-by one bug.
- From: Andreas Tobler <toa at pop dot agri dot ch>
- To: tromey at redhat dot com
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Wed, 07 Jan 2004 06:39:25 +0100
- Subject: Re: [patch] fastjar fix off-by one bug.
- References: <3FFA50D4.9070806@pop.agri.ch> <87u138vr30.fsf@fleche.redhat.com>
Tom Tromey wrote:
"Andreas" == Andreas Tobler <toa@pop.agri.ch> writes:
Andreas> 2004-01-06 Andreas Tobler <a.tobler@schweiz.ch>
Andreas> * jartool.c (make_manifest): Fix off-by-one bug when creating
Andreas> an empty MANIFEST.MF.
I hate to keep tweaking on this, but...
Therfor I send it for review :)
Thanks!
Andreas> +/* This defines the length of the following string:
Andreas> + "Manifest-Version: 1.0\nCreated-By: %s\n\n".
Andreas> + The \n is counted as one character and the %s isn't counted.
Andreas> + The version string length is added below. */
Andreas> +#define MANIFEST_STR_LENGTH 36
How about just doing `strlen (mf) - 1' after computing it?
The idea being, let's get rid of all the bogus-ness in this code and
make it robust in the face of future change.
I certainly don't go to rewrite the tool itself. Wanted just a bug fix.
How about the one below?
Thanks,
Andreas
Index: jartool.c
===================================================================
RCS file: /cvs/gcc/gcc/fastjar/jartool.c,v
retrieving revision 1.24
diff -u -r1.24 jartool.c
--- jartool.c 2 Jul 2003 17:20:54 -0000 1.24
+++ jartool.c 7 Jan 2004 05:36:48 -0000
@@ -313,6 +313,11 @@
/* This holds all options. */
#define OPTION_STRING "-ctxuvVf:m:C:0ME@"
+/* Define the MANIFEST content here to have it easier with calculations
+ below. This is for the case we create an empty MANIFEST.MF. */
+#define MANIFEST_STR "Manifest-Version: 1.0\nCreated-By: "
+#define MANIFEST_END "\n\n"
+
static const struct option options[] =
{
{ "help", no_argument, NULL, OPT_HELP },
@@ -732,13 +737,14 @@
/* if the user didn't specify an external manifest file... */
if(mf_name == NULL){
- int mf_len = 37 + strlen(VERSION);
+
+ int mf_len = strlen(MANIFEST_STR) + strlen(VERSION) +
strlen(MANIFEST_END);
char *mf;
if((mf = (char *) malloc(mf_len + 1))) {
uLong crc;
- sprintf(mf, "Manifest-Version: 1.0\nCreated-By: %s\n\n", VERSION);
+ sprintf(mf, "%s%s%s", MANIFEST_STR, VERSION, MANIFEST_END);
crc = crc32(0L, Z_NULL, 0);