delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/05/11:41:00

From: <ams AT ludd DOT luth DOT se>
Message-Id: <200301051640.h05GesL22679@speedy.ludd.luth.se>
Subject: Re: stubify
In-Reply-To: <3E185CAF.F72A19E9@phekda.freeserve.co.uk> "from Richard Dawe at
Jan 5, 2003 04:26:23 pm"
To: djgpp-workers AT delorie DOT com
Date: Sun, 5 Jan 2003 17:40:54 +0100 (CET)
X-Mailer: ELM [version 2.4ME+ PL78 (25)]
MIME-Version: 1.0
X-MailScanner: Found to be clean
X-MailScanner-SpamScore: s
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

According to Richard Dawe:
> > > > +      v_printf("Using " MINSTACK_ENV_VAR " = %s.\n", env_stack_size);
> > > > +
> > > > +      stubedit_str = malloc( sizeof("stubify ")+strlen(ofilename)+sizeof(" minstack=")+strlen(env_stack_size)+1 );
> > >
> > > Why do you do sizeof("stubify ")? Shouldn't it be strlen? And on "stubedit "?
> > > I.e.: strlen("stubedit ")? As it turns out, the number from the above code is
> > > right.
> > 
> > As strlen("some string") == sizeof("some string") in C, that shouldn't
> > be a surprise. It's for removing an unnecessary function call when we
> > can calculate it statically.
> 
> OK, but shouldn't it be sizeof("stubedit "), since that's what gets written

Oops! Yes, thanks!

> into the string? You could also remove the "+1" at the end, since sizeof will
> include the nul terminator.

Oink! I see. I was wrong after all: strlen("some string") ==
sizeof("some string") - 1. I didn't think of that. The only positive
thing is that I erred(sp?) towards safety...

> How about:
> 
> fprintf(stderr, "%s: illegal minimum stack size specified in environment
> variable " MINSTACK_ENV_VAR ": %s\n", ofilename, env_stack_size);

Great. Incorporated.


Right,

						MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019