9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] varargs question
@ 2009-08-20 13:56 erik quanstrom
  2009-08-20 15:05 ` Russ Cox
  0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2009-08-20 13:56 UTC (permalink / raw)
  To: 9fans

as i was drifting off to sleep the other night,
i was wondering about varargs.  (clearly, it's
time for a vacation.)

and i wondered why kenc doesn't add an argument
count before the first vararg.  (bwc pointed out
that the address following the last vararg would be
more useful.)  va_* could be updated to deal with
the silent extra and abort on access beyond the end
of the actual variable arguments.  a function to check
that list == end could added for the paranoid.

since all code is prototyped these days,
is there any reason why this is a bad idea that i
haven't thought of?

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] varargs question
  2009-08-20 13:56 [9fans] varargs question erik quanstrom
@ 2009-08-20 15:05 ` Russ Cox
  2009-08-20 15:32   ` erik quanstrom
  0 siblings, 1 reply; 3+ messages in thread
From: Russ Cox @ 2009-08-20 15:05 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Aug 20, 2009 at 6:56 AM, erik quanstrom<quanstro@quanstro.net> wrote:
> and i wondered why kenc doesn't add an argument
> count before the first vararg.  (bwc pointed out
> that the address following the last vararg would be
> more useful.)  va_* could be updated to deal with
> the silent extra and abort on access beyond the end
> of the actual variable arguments.  a function to check
> that list == end could added for the paranoid.

what problem are you trying to solve?

the limit would check only that the right number of
argument bytes are consumed, but not that they are
interpreted correctly.  print("%s %d", 1, "hello") would
still crash, as would print("%s", 1, "hello").

#pragma varargck is more precise and can be
done at compile time instead of needing to wait
until the code trips at run time.

russ


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] varargs question
  2009-08-20 15:05 ` Russ Cox
@ 2009-08-20 15:32   ` erik quanstrom
  0 siblings, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2009-08-20 15:32 UTC (permalink / raw)
  To: 9fans

> what problem are you trying to solve?
>
> the limit would check only that the right number of
> argument bytes are consumed, but not that they are
> interpreted correctly.  print("%s %d", 1, "hello") would
> still crash, as would print("%s", 1, "hello").
>
> #pragma varargck is more precise and can be
> done at compile time instead of needing to wait
> until the code trips at run time.

varargck is very effective.  but it only works if the pragma
is used.  (i count 47 functions with ... in /sys/include and
only 27 #pragma varargck argpos.)   and it only works with
functions taking print verbs.  anyone else, is out-of-luck.
for example, the stdio functions.

here are some functions that don't appear to have varargck
that likely should:

auth_wep
ctlerror
hfail
vtDebug
vtFatal
threadsetname
vtlogprint
vtlog

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-20 15:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-20 13:56 [9fans] varargs question erik quanstrom
2009-08-20 15:05 ` Russ Cox
2009-08-20 15:32   ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).