develooper Front page | perl.perl6.internals | Postings from November 2001

RE: [PATCH] Don't count on snprintf

Thread Previous
From:
Brent Dax
Date:
November 30, 2001 15:38
Subject:
RE: [PATCH] Don't count on snprintf
Message ID:
FJELLKOPEAGHOOODKEDPEEOCCKAA.brentdax@cpan.org
Andy Dougherty:
# This patch will temporarily appease tinderbox.perl.org, but it has
# three medium-term problems:
#
# 1.  Configure.pl doesn't figure out HAS_SNPRINTF yet.

That will be hard to deal with.  I can't find a symbol in Config.pm
corresponding to the existence of snprintf.

# 2.  Systems without snprintf() are subject to buffer overflows.
# 3.  The format strings may not be correct.  We need Configure.pl
#     to figure out the correct format strings for INTVALs and NUMVALs.

God, I can see the code already:

	INTVAL foo, baz;
	FLOATVAL bar;
	char *pattern=mem_sys_allocate(64);
	char *target=mem_sys_allocate(64);

	sprintf(pattern, "%s + %s - %s", INTVAL_PATTERN, FLOATVAL_PATTERN,
INTVAL_PATTERN);
	sprintf(target, pattern, foo, bar, baz);

What we really need is our own s(n?)printf:

	Parrot_sprintf(target, "%I + %F - %I", foo, bar, baz);
		/* or some such nonsense */
or even:
	target=Parrot_sprintf("%I + %F - %I); /* like Perl's built-in */

That way, it could even handle Parrot strings natively, perhaps with a
%S code.

By the way, Windows sems to have an _snprintf function with the same
arguments.  The leading underscore is beyond me.  *shrugs*

--Brent Dax
brentdax@cpan.org
Configure pumpking for Perl 6

"Nothing important happened today."
    --George III of England's diary entry for 4-Jul-1776


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About