help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding functions to function.c


From: Ken Smith
Subject: Re: adding functions to function.c
Date: Wed, 12 Jan 2005 09:14:04 -0500
User-agent: Mutt/1.5.6i

This is cool.  I didn't realize it was that easy to add new functions to
gmake.  One thing though for those thinking of cutting and pasting this
code for modification into their gmake source.  (I'm sure JGC realizes
this as the example is pedantic.)  The character string "f" in the below
example is allocated on the stack with a fixed size.  If "argv[0]"
happens to exceed the allocated space, you have a classic buffer overrun
situation.  It may not cause a crash or open a security vulnerability
but it is dangerous to code this way.

  Ken

On Tue, Jan 11, 2005 at 11:30:07PM -0500, John Graham-Cumming wrote:
> On Tue, 2005-01-11 at 13:42, Dill, John wrote:
> > A little while back someone mentioned that it would be possible to add
> > the functions directly to the makefile source.  Is all I do is add the
> > name of the function to the list using STRING_SIZE_TUPLE, and then
> > define my own function?  
> 
> I was the one that suggested you do that.  For example, suppose you were
> me and you egotistically wanted to add the $(jgc TEXT) function which
> printed out John Graham-Cumming followed by the expanded TEXT argument
> you would do this:
> 
> 1. Add a function that does the work:
> 
> static char *
> func_jgc (o, argv, funcname)
>      char *o;
>      char **argv;
>      const char *funcname;
> {
>   char f[256];
>   sprintf( f, "John Graham-Cumming %s", argv[0] );
>   return variable_buffer_output (o, f, strlen(f));
> }
> 
> 2. Add an entry in the function table:
> 
>   { STRING_SIZE_TUPLE("jgc"),           0,  1,  1,  func_jgc},
> 
> which states that the $(jgc) function has maximum one argument which
> should be expanded before the value is passed to func_jgc.
> 
> Now consider this Makefile:
> 
> FOO := is nuts
> 
> all: ; @echo $(jgc $(FOO))
> 
> When using the augmented GNU Make with the $(jgc) function this prints
> 
> John Graham-Cumming is nuts
> 
> $(FOO) is expanded before func_jgc is called because expanding was set
> to 1 and the func_jgc just returns that appropriate string in o.
> 
> John.
> -- 
> John Graham-Cumming
> 
> Home: http://www.jgc.org/
> Work: http://www.electric-cloud.com/
> POPFile: http://getpopfile.org/
> 
> 
> 
> 
> _______________________________________________
> Help-make mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-make




reply via email to

[Prev in Thread] Current Thread [Next in Thread]